>>>>> "SHC" == Shawn H Corey <shawnhco...@gmail.com> writes:

  SHC> Steve Bertrand wrote:
  >> my $month = $ARGV[0] if $ARGV[0];

that is similar to the broken my $foo = 1 if 0 used to make static vars
inside a sub. the assignment won't even happen unless you have a true value.

  SHC> Try:
  SHC> my $month = '';
  SHC> $month = $ARGV[0] if $ARGV[0];

or just use ||:

        my $month = $ARGV[0] || '' ;

then the assignment always happens and the declaration should be critic
clean.

you can even just do:

        my $month = $ARGV[0] ;

since you do a boolean test on $month later on. it will handle the same
logic you have here. but you do a regex on $month and that would trigger
an undef warning if you didn't pass in an arg. so the above code is better.

the rule is never use a statement modifier on a declaration. you can
almost always get what you want with boolean ops.

uri

-- 
Uri Guttman  ------  u...@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to