Home > Archive > PERL Beginners > July 2005 > perl -e "print $#argv;" foo bar baz ---> -1
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
perl -e "print $#argv;" foo bar baz ---> -1
|
|
| beckman 2005-07-24, 8:29 pm |
| I must just completely misunderstand the whole idea of command-line
arguments. I cannot shake the expectation that the above should print
"3" or "4" or something, anything, other than -1. Hints, anyone?
| |
|
| well first off $#argv is index number of the last element in @argv, but
@argv isn't defined so it returns -1; you probably were thinking of
@ARGV (notice case). But for some reason the following says undefined
variable:
perl -e "print $#ARGV" foo bar baz
ARGV: Undefined variable.
but this does work
perl -e "print scalar @ARGV" foo bar baz
3
perhaps one of the perl devs can explain why @ARGV is ok, but $#ARGV is
not.
| |
|
| oh my shell was interpreting the $ so use single quotes:
perl -e 'print $#ARGV' foo bar baz
2
|
|
|
|
|