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
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]