Perl Monk, Perl Meditation | |
PerlMonks |
Re: Copying a value from an element in the ARGV array to a variable...by arturo (Vicar) |
on Sep 17, 2001 at 19:54 UTC ( [id://112884]=note: print w/replies, xml ) | Need Help?? |
Just a note: you can test whether @ARGV has any members with the idiomatic
Two things: @ARGV gets evaluated in a scalar context, which means that what is checked is the *number* of elements in the array; if that number is *not* 0 (i.e. if there are any elements in the array), the test evaluates to true, and the block will be executed. Second note : the *declaration* of $date occurs outside the braces, so when you set $date inside the braces, that change will be visible to other code outside the braces. When you use my inside a set of braces, you're creating a *new* variable that is only visible to code inside the braces. You can see how this works with
Incidentally, you can make your $date setting very compact by using || or the "ternary operator" (see perlop):
if $ARGV[0] evaluates to false ( because it doesn't exist, or was 0 ), then $date gets set to what the yesterday sub returns. HTH. /msg me if you need anything explained.
In Section
Seekers of Perl Wisdom
|
|