my $foo = m/(foo)/ ? $1 : '';
| [reply] [d/l] |
$foo = $1 if /(foo)/;
may be okay, but
my $foo = 1 if /(foo)/;
is not. | [reply] [d/l] [select] |
| [reply] |
$foo = $1 if /(foo)/; may very well be the expected behaviour in certain situations where we want to modify $foo if the match is successfull or leave it otherwise. Using it when declaring a variable is not desirable however. If there is no match, then $foo will not be declared and any attempt to read the scalar later will result in a "variable not declared" error. Of course, this is why we use strict;. Without it, we won't get an error :) defined.
Basically, $foo = $1 if /(foo)/; should really only be used where we might otherwise do a $foo = /(foo)/ ? $1 : $foo; (which is just programatically ugly).
Update: Whoa, was I off base. Read the replies to this node to see the reason :)
| [reply] [d/l] [select] |