in reply to ARGV question
I just can't figure out what's getting assigned to $verboseJust run some experiments...
> cat 705063.pl my $verbose = (@ARGV && $ARGV[0] eq '-v' && shift); if (defined $verbose) { print "verbose:$verbose:\n"; } else { print "verbose not defined\n"; } > > ./705063.pl verbose:0: > ./705063.pl -v verbose:-v: > ./705063.pl -v -b -n verbose:-v: > ./705063.pl -b verbose::
If no arguments are passed to the script, verbose will be 0.
If any arguments are passed to the script, and the 1st is NOT '-v', then verbose seems to be a zero-length string, but not 'undef'. Perhaps a more knowledgable Monk can explain why.
If any arguments are passed to the script, and the 1st is '-v', then verbose is '-v'.
If this behavior is not what you want and you have control over the code, I suggest re-writing it to achieve what you want in a way that you understand.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: ARGV question
by olus (Curate) on Aug 18, 2008 at 22:13 UTC |