in reply to 'my' with 'if 0' retains old value
From perlsyn:
So the following:NOTE: The behaviour of a "my" statement modified with a statement mod +ifier conditional or loop construct (e.g. "my $x if ...") is undefine +d. The value of the "my" variable may be "undef", any previously ass +igned value, or possibly anything else. Don't rely on it. Future ve +rsions of perl might do something different from the version of perl +you try it out on. Here be dragons.
my $v2 = -2 if 0;
Will have undefined and probably unexp(?:exted|licible) behavior. Don't do it! Don't use a my assignment with a conditional!
Define your variable first, then set it using the conditional.
|
---|