[17246] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 4668 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 19 21:05:38 2000

Date: Thu, 19 Oct 2000 18:05:15 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <972003914-v9-i4668@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 19 Oct 2000     Volume: 9 Number: 4668

Today's topics:
    Re: Build up an array of "matching strings" <ren.maddox@tivoli.com>
    Re: Build up an array of "matching strings" (Martien Verbruggen)
    Re: converting a binary file to ascii <pauls_spam_no@pauls.seanet.com>
        Converting tabular data to records <skip@northend.com>
    Re: Converting tabular data to records <jeff@vpservices.com>
    Re: Cookieless operation <iltzu@sci.invalid>
        Diagnosing memory hoggishness (Andrew J. Perrin)
        Download via HTTPS? rathmore@tierceron.com
    Re: Download via HTTPS? <anders@wall.alweb.dk>
    Re: File::Find pruning <ddunham@redwood.taos.com>
    Re: File::Find pruning <james@NOSPAM.demon.co.uk>
    Re: finding mode and median of an array of numbers (Craig Berry)
    Re: finding mode and median of an array of numbers <iltzu@sci.invalid>
    Re: finding mode and median of an array of numbers <godzilla@stomp.stomp.tokyo>
    Re: formatting html email to send via sendmail <bart.lateur@skynet.be>
        Going from Linux RPM Perl 5.00503 to compiled 5.6.0 - l <scott@lund.com>
    Re: Going from Linux RPM Perl 5.00503 to compiled 5.6.0 <anders@wall.alweb.dk>
        Help uploading multiple files <webmaster@californiaspecial.com>
    Re: how do i find file size? <anders@wall.alweb.dk>
    Re: how do i find file size? (Martien Verbruggen)
    Re: how do i find file size? <me@privacy.net>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: 19 Oct 2000 16:46:44 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Build up an array of "matching strings"
Message-Id: <m3pukwec6z.fsf@dhcp11-177.support.tivoli.com>

fgont@my-deja.com writes:

> Suppose I have a variable (say $a) that contains e-mail addresses.
> For example:
> 
> $_ = "fnt\@sohome.net, lcho\@elcho.com.ar>";
> 
> 
> and I want to build up an array with the e-mail addresses.
> 
> I tried to do it by doing de following:
> 
> $_= $a;
> $temp=0;
> 
> while(m/[\w\-\.]+\@[\w\-]+(\.[\w\-]+)+/g){
>       $arrayofadd[$temp]= $&;
>       $temp++;
> }
> 
> but it seems that my regexp doesn't match anything.
> 
> Note: the problem IS NOT the regex, as I used it outside the while loop,
> and it works Ok.

This worked fine for me, though one silly problem that I presumed was
just a typo is that you say $a has the value, but you actually show $_
having the value.  Then you assign $a to $_, possibly overwriting the
value.

If that isn't the problem, then I do not know what is, because, as I
said, it worked fine for me.

Also, please look at the several recent threads on parsing email
addresses for lots of discussion on why you don't really want to use
this regex to do so.

-- 
Ren Maddox
ren@tivoli.com


------------------------------

Date: Fri, 20 Oct 2000 10:09:16 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Build up an array of "matching strings"
Message-Id: <slrn8uuvos.fji.mgjv@martien.heliotrope.home>

On Thu, 19 Oct 2000 21:01:45 GMT,
	fgont@my-deja.com <fgont@my-deja.com> wrote:
> Hi!
> 
> Suppose I have a variable (say $a) that contains e-mail addresses.
> For example:
> 
> $_ = "fnt\@sohome.net, lcho\@elcho.com.ar>";

Here you assign something to $_

> and I want to build up an array with the e-mail addresses.
> 
> I tried to do it by doing de following:
> 
> $_= $a;

And here you assign something else, possibly empty. Note that $a is a
global variable used by sort subroutines. It is hardly ever a good idea
to use it outside of sort subs.

> $temp=0;
> 
> while(m/[\w\-\.]+\@[\w\-]+(\.[\w\-]+)+/g){
>       $arrayofadd[$temp]= $&;
>       $temp++;
> }

And, as long as something valid is in $_, this works fine for me. Just a
few remarks: Using $& is not a good idea, because it slows _every_
regular expression match in your program down. Use capturing parentheses
instead. If you do that, you have to make sure to make the other
grouping brackets non-capturing. You can also use m//g in a list context
to do what you did above:

@arrayofadd = /([\w\-\.]+\@[\w\-]+(?:\.[\w\-]+)+)/g;

Note the two changes to the RE. I use capturing brackets around the
whole thing, and changed the grouping ones to non-capturing.

# perldoc perlre

You also don't _have_ to match against $_. 

$addresses = 'fnt@sohome.net, lcho@elcho.com.ar>'
@arrayofadd = $addresses =~ /([\w\-\.]+\@[\w\-]+(?:\.[\w\-]+)+)/g;

Of course, if your intention is to capture email addresses, you should
check perl FAQ 9

# perldoc perlfaq9

as well as the lengthy thread that is going on on this group about just
that. You're not capturing all valid email addresses. But this may very
well be good enough for your needs.

> but it seems that my regexp doesn't match anything.
> 
> Note: the problem IS NOT the regex, as I used it outside the while loop,
> and it works Ok.

I think the problem was that you didn't have in $_ what you thought you
had.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | +++ Out of Cheese Error +++
Commercial Dynamics Pty. Ltd.   | Reinstall Universe and Reboot +++
NSW, Australia                  | 


------------------------------

Date: Thu, 19 Oct 2000 16:31:41 -0700
From: Paul Spitalny <pauls_spam_no@pauls.seanet.com>
Subject: Re: converting a binary file to ascii
Message-Id: <39EF845D.CBCCFC3A@pauls.seanet.com>



Larry Rosler wrote:

>
>
> Apparently your input file has 8-byte alignment screwed up.  If this is
> due to a "\12" in the binary data, it can only be because the file was
> *written* as a text file, so what was written was really "\15\12".
>
> To verify this conjectore, test again without the (correct) 'binmode
> NEW;' statement.  Then any "\15\12" sequence in the input file will be
> converted (back?) to "\12" and the program should work.
>
>
> You might find unpacking the file with 'H*' format a useful way of
> seeing what is really there.
>
> --
> (Just Another Larry) Rosler
>

Hi Larry,
Right you are! Here is what I get... I print the output line # (just for
convenience), then do an  unpack using "H*" and the unpack using "d" . See how
line # 14 with the (hex) 0d and 0a is where things start to go astray.

1     00f7fcf4cf03c73e     2.74358891508189e-006
2     5327c018bd7d2dbf     -0.000224999745455807
3     0000000000000000     0
4     0000006febacfbbd     -4.02731055969274e-010
5     0000000000000000     0
6     a334d21ff8c3483f     0.000755783228343927
7     00307602fbda48bf     -0.000758526385582936
8     00003e13abdcfdbd     -4.34549080089396e-010
9     0000000000000000     0
10     0000000000000000     0
11     00485baafeff0140     2.24999745455807
12     0000000000000240     2.25
13     00a42d55ffff0140     2.24999872727903
14     cffab7ae3e1e0d0a     2.95908505230826e-260
15     4000485baafeff01     4.77753130050077e-299

I coded it like this:

open(BIN,'<purebin.dat');
open(OUT,'>decoded.dat');
binmode(BIN);
$count = 0;
seek(DAT, $point, 0);
while (read(BIN,$in,8))
  {
  $count ++;
  $foo = unpack("H*",$in);
  $bar = unpack("d",$in);
  print OUT "$count $foo $bar\n";
  }
close(BIN);
close(OUT);

Any thoughts on how to cure myself of this CR, lF dis-ease??

By the way, the file I am struggling with is written by a cad tool (a SPICE
simulator). The format is entirely due to the guys at the simulator factory!!

Thanks for all your help to-date, thanks a whole lot!

Paul

--
To respond to this posting, remove -nospam- from my email address.
Sorry for the inconvenience




------------------------------

Date: Thu, 19 Oct 2000 20:22:47 -0400
From: Skip Lombardi <skip@northend.com>
Subject: Converting tabular data to records
Message-Id: <39EF9057.E5502F28@northend.com>

I have a really ugly data set, and I can get it into a form that looks
something like this:

Skill 1
Unspecified
16 Oct 2000
04 Nov 2000
1
0.75
Absolute
P
0.02


Now, the task is getting this data into a record on a single line.  Does
anyone have any suggestions?

Best regards,
Skip Lombardi



------------------------------

Date: Thu, 19 Oct 2000 17:48:58 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Converting tabular data to records
Message-Id: <39EF967A.981A9303@vpservices.com>

Skip Lombardi wrote:
> 
> I have a really ugly data set, and I can get it into a form that looks
> something like this:
> 
> Skill 1
> Unspecified
> 16 Oct 2000
> 04 Nov 2000
> 1
> 0.75
> Absolute
> P
> 0.02
> 
> Now, the task is getting this data into a record on a single line.  Does
> anyone have any suggestions?

Giving a single example without explaining what about your data is
consistent between that and other examples is pretty unhelpful.  What
separates that record from the next record (a blank line?)  Do all
records start with the word "Skill" capitalized and followed by a
number?   Is it possible that individual fields within the record also
start with the word Skill capitalized and followed by a number?  Are
there always exactly 9 lines in a record?  Are fields within the record
ever blank, and if so, how are they currently stored?  What format do
you want the one-line record stored as (fixed width? CSV? tab
delimited?)

Without knowing the answers to those questions, there's really not much
way to answer you.  It may be there is a fairly simple solution to your
question but there's no way to know with what you've provided so far. 
Send more.

-- 
Jeff


------------------------------

Date: 19 Oct 2000 23:14:43 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: Cookieless operation
Message-Id: <971996908.21815@itz.pp.sci.fi>

In article <8smo6o$q46$1@nnrp1.deja.com>, yossariancomputing@my-deja.com wrote:
>
>Security. That was good advice and so I've taken on board the stuff
>regarding security and checking IP address and browser.  When items get
>added to a cart, I check if it's an existing cart.  If so, I then check
>both the connecting browser and it's IP address, and throw out an error
>if they don't match the cartid.

Both of those might change during a valid session.  In particular,
proxy hierarchies can make the originating IP address appear different
on each request.

Just put a random password in the form and check *that* against the
cart IDs.  If you're really paranoid, issue a new password for each
request.  (Incidentally, that way you'll also notice if someone
accidentally submits the same form twice.)

[Followups set to a more appropriate group.]

-- 
Ilmari Karonen - http://www.sci.fi/~iltzu/
Please ignore Godzilla  | "By promoting postconditions to
and its pseudonyms -    |  preconditions, algorithms become
do not feed the troll.  |  remarkably simple."  -- Abigail



------------------------------

Date: 19 Oct 2000 20:11:46 -0400
From: aperrin@demog.berkeley.edu (Andrew J. Perrin)
Subject: Diagnosing memory hoggishness
Message-Id: <u66mocqwt.fsf@demog.berkeley.edu>

Greetings. I'm writing a package that does some analyses of text,
and the analyses often involve storing large (~400,000 elements)
arrays of words and references at once.  I'm having some problems with
memory; specifically, under linux the test script dies with an "Out of
Memory!", and under NT it just dies quietly.

I know there are significant inefficiencies in the way my package uses
memory, but many of them have real purposes.  What I'd like is some
way to *systematically* note where in the script there are big jumps
in memory usage.  Since these scripts can run for hours or even days,
it's not practical for me to sit there and watch 'top' constantly.
Does anyone have a clever idea of how to write the script's footprint
to a file on a regular basis, and even potentially how to map what
variables are taking what amounts of RAM at each time?

Many thanks.

-- 
----------------------------------------------------------------------
Andrew J Perrin - Ph.D. Candidate, UC Berkeley, Dept. of Sociology  
Chapel Hill, North Carolina, USA - http://demog.berkeley.edu/~aperrin
        aperrin@socrates.berkeley.edu - aperrin@igc.apc.org


------------------------------

Date: Fri, 20 Oct 2000 00:01:50 GMT
From: rathmore@tierceron.com
Subject: Download via HTTPS?
Message-Id: <8so21a$ujd$1@nnrp1.deja.com>

Does anyone know of a module that allows you to download a file from an
https server? I searched CPAN but didn't have much luck finding what I
think I'm after...



Sent via Deja.com http://www.deja.com/
Before you buy.


------------------------------

Date: Fri, 20 Oct 2000 02:15:59 +0200
From: Anders Lund <anders@wall.alweb.dk>
Subject: Re: Download via HTTPS?
Message-Id: <N9MH5.8109$Tq1.286067@news010.worldonline.dk>

rathmore@tierceron.com wrote:

> Does anyone know of a module that allows you to download a file from an
> https server? I searched CPAN but didn't have much luck finding what I
> think I'm after...

LWP
       Libwww-perl is a collection of Perl modules which provides
       a simple and consistent application programming interface
       (API) to the World-Wide Web.  The main focus of the
       library is to provide classes and functions that allow you
       to write WWW clients, thus libwww-perl is a WWW client
       library. The library also contain modules that are of more
       general use. 

(from the LWP documentation)


-anders
-- 
[ the word wall - and the trailing dot - in my email address
is my _fire_wall - protecting me from the criminals abusing usenet]


------------------------------

Date: Thu, 19 Oct 2000 23:26:29 GMT
From: Darren Dunham <ddunham@redwood.taos.com>
Subject: Re: File::Find pruning
Message-Id: <FqLH5.99$qa2.87346@news.pacbell.net>

James Taylor <james@nospam.demon.co.uk> wrote:

>> Note that pruning doesn't work if you're using finddepth
>> or the bydepth attribute.

> Really? My understanding of finddepth() is that it scans the
> directory structure depth first. Why should that preclude the
> possibility of pruning?

> I'm using find() without the bydepth attribute but strangely it seems
> to search depth first anyway. The port of Perl (or should that be perl)
> for my OS (Acorn RISC OS in fact) has had many of the standard modules
> hacked to be more portable by the porter, so I suppose it's possible
> that he broke something in doing so.

> Having said that the idea of a recursive routine doing a breadth first
> traversal does seem rather odd, because it would have to remember the
> prune settings for all the subdirectories before entering any one of
> them. Have I missed something about depth first versus breadth first?

The docs are a little bit of a misnomer.  It's not that finddepth does
depth-first and find does breadth-first.

It's when a given directory is reported.  They're both 'depth-first' in
the normal sense of the word.  But with a simple A/B structure find
reports

 ./A
 ./A/B

and finddepth reports
 ./A/B
 ./A

Finddepth will not report a directory until any deeper files have been
listed.  Find reports a directory before any deeper files have been
listed.

One might be a good idea if you were needing to create things (might
want to mkdir A before touching A/B) and another way might be good if
you were keeping track of timestamps  (no good to correct the mtime of A
if you're about to create A/B).

Subtle, and not normally interesting in the vast majority of cases where
you don't really care what order you get the files.

Personally, I would think pruning would work *better* without finddepth
due to those differences.

Here's a sample run
find       finddepth
1          1/2/3/a 
1/2	   1/2/3   
1/2/3	   1/2/a   
1/2/3/a	   1/2/b   
1/2/a	   1/2     
1/2/b	   1/a     
1/a	   1/22    
1/22	   1       

Notice in both cases all subdirectories of 1/2 are listed before 1/a or
1/22.  That would not be true in a breadth-first search.

-- 
Darren Dunham                                           ddunham@taos.com
Unix System Administrator                    Taos - The SysAdmin Company
Got some Dr Pepper?                           San Francisco, CA bay area
      < Please move on, ...nothing to see here,  please disperse >


------------------------------

Date: Fri, 20 Oct 2000 00:56:03 +0100
From: James Taylor <james@NOSPAM.demon.co.uk>
Subject: Re: File::Find pruning
Message-Id: <ant192303256fNdQ@oakseed.demon.co.uk>

In article <FqLH5.99$qa2.87346@news.pacbell.net>, Darren Dunham
<URL:mailto:ddunham@redwood.taos.com> wrote:
>
> James Taylor <james@nospam.demon.co.uk> wrote:
> > Having said that the idea of a recursive routine doing a breadth first
> > traversal does seem rather odd, because it would have to remember the
> > prune settings for all the subdirectories before entering any one of
> > them. Have I missed something about depth first versus breadth first?
> 
> The docs are a little bit of a misnomer.  It's not that finddepth does
> depth-first and find does breadth-first.
> 
> It's when a given directory is reported.  They're both 'depth-first' in
> the normal sense of the word.  But with a simple A/B structure find
> reports
> 
> ./A
> ./A/B
> 
> and finddepth reports
> ./A/B
> ./A
[snip lots of useful description and examples, thanks]

Ah, I see. So rather than "depth first" it should be "deepest first".
I think the docs should be updated to reflect that. Who is responsible
for maintaining this kind of thing?

-- 
James Taylor <james (at) oakseed demon co uk>
PGP key available ID: 3FBE1BF9
Fingerprint: F19D803624ED6FE8 370045159F66FD02



------------------------------

Date: Thu, 19 Oct 2000 22:56:23 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: finding mode and median of an array of numbers
Message-Id: <suuv0n9dhidn17@corp.supernews.com>

Godzilla! (godzilla@stomp.stomp.tokyo) wrote:
: Some challenges for you, Mr. Berry.
[snip]

Depends on your definitions for mode when there are 2+ highest counts, and
for median of an even number of elements.

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "Quidquid latine dictum sit, altum viditur."
   |


------------------------------

Date: 19 Oct 2000 23:30:33 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: finding mode and median of an array of numbers
Message-Id: <971997719.27332@itz.pp.sci.fi>

In article <suumg35lh7bfc9@corp.supernews.com>, Craig Berry wrote:
>
>my $median = (sort { $a <=> $b } @ARGV)[$#ARGV / 2];      

This, of course, only works if the median is well defined among the
elements -- that is, if the number of elements is odd or the two
middle elements in the sorted list are equal.

>my %h;        
>$h{$_}++ foreach @ARGV;
>my $mode = (sort { $h{$a} <=> $h{$b} } keys %h)[-1];

Similarly, this only works if there is a single mode.  If there are
multiple modes, the result could be any one of them.

-- 
Ilmari Karonen - http://www.sci.fi/~iltzu/
Please ignore Godzilla  | "By promoting postconditions to
and its pseudonyms -    |  preconditions, algorithms become
do not feed the troll.  |  remarkably simple."  -- Abigail



------------------------------

Date: Thu, 19 Oct 2000 17:32:48 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: finding mode and median of an array of numbers
Message-Id: <39EF92B0.EA7D4CD9@stomp.stomp.tokyo>

Craig Berry wrote:
> 
> Godzilla! wrote:

> : Some challenges for you, Mr. Berry.
> [snip]
 
> Depends on your definitions for mode when there are
> 2+ highest counts, and for median of an even number
> of elements.


Mode is the most frequently occurring number
within a number set. Mode requires a minimum
of two same numbers. If Mode contains sets
of equal amounts of multiple numbers, Mode is
a multiplicity number set.

Median is the middle or center number for an
odd numbered number set. Median is the average
of the two intermost or two middle numbers for
an even numbered number set.

There are no other definitions, Mr. Berry,
nor are there exceptions to these definitions.

If I elected to write code for this, my code
would be based on array element numbers rather
than actual number content.

Mode is easy enough to find; two or more of
the same element or, elements for a multiplicity
number set.

Median is a bit more challenging.

Setting a given, first element reference number
of an array is clearly zero. An odd numbered 
array would display $#Array as an even number,
just to keep us challenged, if not confused.
I believe Mr. Wall did this to us purposely.

For an odd numbered number set, or more appropriate,
an odd numbered array set, divide $#Array by two and
you have your median element.

For an even numbered array set, add one to $#Array,
divide it by two and you have your upper element of
a two element set, $variable_high. Subtract one from
this variable's reference number, and you have your 
lower element of this set, $variable_low. Add both 
variables, divide by two and you have your median for
an even numbered array.

For the reader, remind yourself while counting on your
fingers, your thumb is zero. heh heh hehhhh...

Nice aspect of this method, Mr. Berry, you never have
to know what numbers you actually have; you work solely
with array element reference numbers.


* ponders if I worded this right *

It is tough when you have eleven fingers and
your thumb amounts to zilch.


Godzilla!
-- 
Dr. Kiralynne Schilitubi ¦ Cooling Fan Specialist
UofD: University of Duh! ¦ ENIAC Hard Wiring Pro
BumScrew, South of Egypt ¦ HTML Programming Class


------------------------------

Date: Thu, 19 Oct 2000 22:12:35 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: formatting html email to send via sendmail
Message-Id: <hbsuussal6tph4equthg1uqdi20asajj62@4ax.com>

Scott Corneil wrote:

>I'm having difficulty formatting the headers correctly to send html
>email messages.  I can't use a module like MIME::Lite because I have no
>root access, and the server admins don't allow modules to be installed.

Eh? They can't stop you. MIME::Lite is a pure perl module. If you can
isntall a script, you can install this module. All you need is to set
aside a dedicated directory, preferably one that isn't accessible
through HTTP, Put the file MIME/Lite.pm in it, and use the module "lib"
to add it to your @INC.

-- 
	Bart.


------------------------------

Date: Thu, 19 Oct 2000 14:39:16 -0700
From: Scott Chapman <scott@lund.com>
Subject: Going from Linux RPM Perl 5.00503 to compiled 5.6.0 - libraries are not in @INC now!  Help!
Message-Id: <m7quus8gpca9snna5n9nus5e9srfhoeu1d@4ax.com>

I've seen this a number of times when I've started on a RPM version of
Perl and later compile the latest version and install it.  My @INC is
not current and some programs complain like this:

>Can't locate strict.pm in @INC (@INC contains: /usr/lib/perl5/5.00503/i386-linux
> /usr/lib/perl5/5.00503 /usr/lib/perl5/site_perl/5.005/i386-linux /usr/lib/perl5
>/site_perl/5.005 .) at ./Configure line 9.

strict is now located in:
/usr/local/lib/perl5/5.6.0/strict.pm

How do I straighten out this mess?

Cordially,
Scott.



------------------------------

Date: Fri, 20 Oct 2000 01:04:52 +0200
From: Anders Lund <anders@wall.alweb.dk>
Subject: Re: Going from Linux RPM Perl 5.00503 to compiled 5.6.0 - libraries are not in @INC now!  Help!
Message-Id: <67LH5.8096$Tq1.284243@news010.worldonline.dk>

Scott Chapman wrote:

> I've seen this a number of times when I've started on a RPM version of
> Perl and later compile the latest version and install it.  My @INC is
> not current and some programs complain like this:
> 
> >Can't locate strict.pm in @INC (@INC contains:
> >/usr/lib/perl5/5.00503/i386-linux
> > /usr/lib/perl5/5.00503 /usr/lib/perl5/site_perl/5.005/i386-linux
> > /usr/lib/perl5
> >/site_perl/5.005 .) at ./Configure line 9.
> 
> strict is now located in:
> /usr/local/lib/perl5/5.6.0/strict.pm
> 
> How do I straighten out this mess?

Did you uninstall the rpm's? Most rpm packages should have scripts to clean 
up your system when you uninstalls them.

Btw, is you linux distributor really that slow?
My local Mandrake mirror has a perl-5.6-17mdk.rpm from October 6th.

-anders

-- 
[ the word wall - and the trailing dot - in my email address
is my _fire_wall - protecting me from the criminals abusing usenet]


------------------------------

Date: Thu, 19 Oct 2000 22:36:28 GMT
From: Jon Hanna <webmaster@californiaspecial.com>
Subject: Help uploading multiple files
Message-Id: <8snt1c$qbl$1@nnrp1.deja.com>

I'm new to perl, but I've had pretty good luck modifying the Upscreens
script. Everything works fine, but I do have one question.

My form currently allows up to 5 jpg files to be uploaded, however the
script only recognizes the first file. Any way to modify the script so
it recognizes all 5 files from the upload fields? Maybe something to do
with the "$onnum != 11" or the "my $file" lines?


My script is pasted below. Thanks for any help!

Jon


############# -->
# Upload Data

use CGI;
$onnum = 1;
while ($onnum != 11) {
my $req = new CGI;
my $file = $req->param("FILE$onnum");
$descr = $req->param("descr");
$year = $req->param("year");
$persurl = $req->param("persurl");
$persweb = $req->param("persweb");
$location = $req->param("location");
$persname = $req->param("persname");
$persemail = $req->param("persemail");
if ($file ne "") {
my $fileName = $file;
$fileName =~ s!^.*(\\|\/)!!;
$newmain = $fileName;
if ($allowall ne "yes") {
if (lc(substr($newmain,length($newmain) - 4,4)) ne $theext){
$filenotgood = "yes";
}
}
if ($filenotgood ne "yes") {
open (OUTFILE, ">$basedir/$fileName");
print "$basedir/$fileName<br>";
while (my $bytesread = read($file, my $buffer, 1024)) {
print OUTFILE $buffer;
}
close (OUTFILE);
}
}
$onnum++;
}

############## -->
# Data to Page

   open(MAIN,"$htmldir") || die $!;
   @main = <MAIN>;
   close(MAIN);

   open(MAIN,">$htmldir") || die $!;
   if ($followup == 0) {
      foreach $main_line (@main) {
         if ($main_line =~ /<!--begin-->/) {
            print MAIN "<!--begin-->\n";
            print MAIN "<!-- ______GALLERY ITEM BEGIN______ -->\n";
            print MAIN "  <div align=center><a href=$picurl/
$newmain><img width=100 src=$tnurl/tn_$newmain></a>\n";
            print MAIN "<table border=0 cellpadding=0 cellspacing=0
width=650 bgcolor=#002828>\n";
            print MAIN " <tr>\n";
            print MAIN " <td bgcolor=#7C7352 colspan=2 height=6><img
height=1 src=http://californiaspecial.com/images/sg-clear.gif
width=10></td>\n";
            print MAIN " </tr>\n";
            print MAIN " <tr>\n";
            print MAIN " <td bgcolor=#000000 align=left valign=top
width=50%>\n";

            print MAIN "<table border=0 cellpadding=3 cellspacing=2
width=325 bgcolor=#002828>\n";
            print MAIN " <tr>\n";
            print MAIN "  <td bgcolor=#000000 align=left valign=top
width=50%><font color=#AE9F80 size=-1><b>YEAR: </b></font><font size=-
1>$year</font></td>\n";
            print MAIN " </tr>\n";
            print MAIN " <tr>\n";
            print MAIN "  <td bgcolor=#000000 align=left
valign=top><font color=#AE9F80 size=-1><b>OWNER: </b></font><font size=-
1>$persname</font></td>\n";
            print MAIN " </tr>\n";
            print MAIN " <tr>\n";
            print MAIN "  <td bgcolor=#000000 align=left
valign=top><font color=#AE9F80 size=-1><b>LOCATION: </b></font><font
size=-1>$location</font></td>\n";
            print MAIN " </tr>\n";
            print MAIN " <tr>\n";
            print MAIN "  <td bgcolor=#000000 align=left
valign=top><font color=#AE9F80 size=-1><b>E-MAIL: </b></font><font
size=-1><a href=mailto:$persemail>$persemail</a></font></td>\n";
            print MAIN " </tr>\n";
            print MAIN " <tr>\n";
            print MAIN "  <td bgcolor=#000000 align=left
valign=top><font color=#AE9F80 size=-1><b>WEB PAGE: </b></font><font
size=-1><a href=$persurl>$persweb</a></font></td>\n";
            print MAIN " </tr>\n";
            print MAIN "</table>\n";
            print MAIN " </td>\n";

            print MAIN " <td bgcolor=#000000 align=left valign=top
width=50%>\n";
            print MAIN "<table border=0 cellpadding=3 cellspacing=2
width=325 bgcolor=#002828>\n";
            print MAIN " <tr>\n";
            print MAIN "  <td bgcolor=#000000 align=left
valign=top><font color=#AE9F80 size=-1><b>FEATURES: </b></font><font
size=-1>$descr</font></td>\n";
            print MAIN " </tr>\n";
            print MAIN "</table>\n";

            print MAIN " </td>\n";
            print MAIN " </tr>\n";
            print MAIN "</table>\n";
            print MAIN "<p>\n";
            print MAIN "<br>\n";
            print MAIN "<p>\n";
            print MAIN "<!-- ______GALLERY ITEM END______ -->\n";
         }
         else {
            print MAIN "$main_line";
         }
      }
      close(MAIN);
   }

################# -->
# After Data Code

print "Content-type: text/html\n";
print "Location:$back\n\n";


# End of Script
###############






###################### -->
# Grabs info from form

if ($FORM{'descr'} =~ /.*\@.*\..*/) {
   $descr = "$FORM{'descr'}";
   $descr =~ s/\&/\&amp\;/g;
   $descr =~ s/"/\&quot\;/g;
}


Sent via Deja.com http://www.deja.com/
Before you buy.


------------------------------

Date: Fri, 20 Oct 2000 00:59:28 +0200
From: Anders Lund <anders@wall.alweb.dk>
Subject: Re: how do i find file size?
Message-Id: <22LH5.8093$Tq1.284054@news010.worldonline.dk>

EM wrote:

> whats the perl code to find the size of a file?

my $size = (stat $file)[7]; #bytes

perldoc -f stat for more..

> also does anyone know any code to download a binary file off a http server
> and save it to a file
> i have a code for this already
> 
> $url = http://www.wherever.com/file.zip;
> use LWP::Simple;
> $file = get($url);
> 
> but this code is very unreliable & slow and often gets corrupted/not fully
> downloaded files
> 

There is bunches of modules dealing w/ FTP.
go to http://search.cpan.org and type "FTP" in the little box, then hit 
<RETURN>...

-anders
-- 
[ the word wall - and the trailing dot - in my email address
is my _fire_wall - protecting me from the criminals abusing usenet]


------------------------------

Date: Fri, 20 Oct 2000 10:26:16 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: how do i find file size?
Message-Id: <slrn8uv0oo.fji.mgjv@martien.heliotrope.home>

On Thu, 19 Oct 2000 21:34:05 GMT,
	EM <me@privacy.net> wrote:
> whats the perl code to find the size of a file?

my $file_size = -s $filename;

or

my $file_size = (stat $filename)[7];

# perldoc -f -s
# perldoc -f stat

> also does anyone know any code to download a binary file off a http server
> and save it to a file
> i have a code for this already
> 
> $url = http://www.wherever.com/file.zip;
> use LWP::Simple;
> $file = get($url);
> 
> but this code is very unreliable & slow and often gets corrupted/not fully
> downloaded files

It is generally better to post separate questions separately, because
that prevents discussion threads to become split up, and only half
useful to people who are searching the group.

I don't understand what the problem with the above is. Are you sure that
the 'corruption' occurs there, or maybe it occurs when you save the data
to a file? Did you use binmode?

# perldoc -f binmode

About the slowness: LWP::Simple loads the file into memory. If you don't
have enough, things may start trashing. Is it any faster if you use
other methods? Consistently?

Maybe instead of using get, you should use getstore($url, $filename).
That way both problems I mentioned should go away.

# perldoc LWP::Simple

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | In the fight between you and the
Commercial Dynamics Pty. Ltd.   | world, back the world - Franz Kafka
NSW, Australia                  | 


------------------------------

Date: Thu, 19 Oct 2000 23:39:00 GMT
From: "EM" <me@privacy.net>
Subject: Re: how do i find file size?
Message-Id: <oCLH5.7116$44.21410@news.iol.ie>

Thanks alot!!!
getstore($url, $filename) works perfectly
but
is there a way i can show in the browser the current status of the transfer?



"Martien Verbruggen" <mgjv@tradingpost.com.au> wrote in message
news:slrn8uv0oo.fji.mgjv@martien.heliotrope.home...
> On Thu, 19 Oct 2000 21:34:05 GMT,
> EM <me@privacy.net> wrote:
> > whats the perl code to find the size of a file?
>
> my $file_size = -s $filename;
>
> or
>
> my $file_size = (stat $filename)[7];
>
> # perldoc -f -s
> # perldoc -f stat
>
> > also does anyone know any code to download a binary file off a http
server
> > and save it to a file
> > i have a code for this already
> >
> > $url = http://www.wherever.com/file.zip;
> > use LWP::Simple;
> > $file = get($url);
> >
> > but this code is very unreliable & slow and often gets corrupted/not
fully
> > downloaded files
>
> It is generally better to post separate questions separately, because
> that prevents discussion threads to become split up, and only half
> useful to people who are searching the group.
>
> I don't understand what the problem with the above is. Are you sure that
> the 'corruption' occurs there, or maybe it occurs when you save the data
> to a file? Did you use binmode?
>
> # perldoc -f binmode
>
> About the slowness: LWP::Simple loads the file into memory. If you don't
> have enough, things may start trashing. Is it any faster if you use
> other methods? Consistently?
>
> Maybe instead of using get, you should use getstore($url, $filename).
> That way both problems I mentioned should go away.
>
> # perldoc LWP::Simple
>
> Martien
> --
> Martien Verbruggen              |
> Interactive Media Division      | In the fight between you and the
> Commercial Dynamics Pty. Ltd.   | world, back the world - Franz Kafka
> NSW, Australia                  |




------------------------------

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V9 Issue 4668
**************************************


home help back first fref pref prev next nref lref last post