Jenda,

Thanks for a very impressive answer.

Angus

-----Original Message-----
From: Jenda Krynicky [mailto:[EMAIL PROTECTED]]
Sent: 18 March 2002 12:05
To: Laycock, Angus; [EMAIL PROTECTED]
Subject: RE: @ARGV question


From: "Laycock, Angus" <[EMAIL PROTECTED]>
> $ARGV[$count] represents the index of the array. I am passing in
> parameters and some contain space between two words and I noticed that
> using while (<@ARGV>) it loops the exact amount of times per words,
> not per parameter.

I see. So you wanted

        $count = 0;
        while (<@ARGV>) {
                $count++;
                print "$count $_\n";
        }

right? well ... don't do that OK?
Especialy since you don't really understand what's going on in
there.

Try this

        $count = 0;
        while (<foo bar *.pl *.a_complete_noNsense>) {
                $count++;
                print "$count $_\n"
        }

Od run your script with
        perl the_script.pl foo bar *.pl *.a_complete_noNsense

Do you see the result? <@ARGV> doesn't only split by spaces as
you might have thought. It also treats each word as a filename
mask and returns all files in current directory that match it.

So what happens is not

        $count = 0;
        foreach $item (@ARGV) {
                foreach (split ' ', $item) {
                        $count++;
                        print "$count $_\n"
                }
        }
        # loop over @ARGV, split each item on spaces and loop over
        # the words

but

        $count = 0;
        $tmp = "@ARGV";
        # write the items in @ARGV to a string and separate them
        # by $" which is by default space
        @files = glob $tmp;
        foreach (@files) {
                $count++;
                print "$count $_\n"
        }

If you happen to need to treat the parameters as filename masks
and get the matching filenames I'd recomend using Wild.pm or
G.pm ( http://Jenda.Krynicky.cz/#G )

Jenda

=========== [EMAIL PROTECTED] == http://Jenda.Krynicky.cz ==========
There is a reason for living. There must be. I've seen it somewhere.
It's just that in the mess on my table ... and in my brain.
I can't find it.
                                        --- me


------------------------------------------------------------------------------
This message is intended only for the personal and confidential use of the designated 
recipient(s) named above.  If you are not the intended recipient of this message you 
are hereby notified that any review, dissemination, distribution or copying of this 
message is strictly prohibited.  This communication is for information purposes only 
and should not be regarded as an offer to sell or as a solicitation of an offer to buy 
any financial product, an official confirmation of any transaction, or as an official 
statement of Lehman Brothers.  Email transmission cannot be guaranteed to be secure or 
error-free.  Therefore, we do not represent that this information is complete or 
accurate and it should not be relied upon as such.  All information is subject to 
change without notice.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to