in reply to Re^2: Duh. 'my' scope in if else blocks.
in thread Duh. 'my' scope in if else blocks.
doom's explanation is wrong. It has nothing to do with order. Even if you fixed the order, it still wouldn't work.
(my $t = shift) and print $t; # Fails.
Variables cannot be used (by name) in the statement in which they are declared. This allows statements such as my $t = $t; to work.
print $t if (my $t = shift); # Fails. my $t = shift; print $t if $t; # Ok. if (my $t = shift) { print $t; } # Ok.
|
|---|