This is documented in perlsub:
Similarly, in the conditionalthe scope of $answer extends from its declaration through the rest of that conditional, including any elsif and else clauses, but not beyond it.if ((my $answer = <STDIN>) =~ /^yes$/i) { user_agrees(); } elsif ($answer =~ /^no$/i) { user_disagrees(); } else { chomp $answer; die "'$answer' is neither 'yes' nor 'no'"; }
In reply to Re: Duh. 'my' scope in if else blocks.
by bobf
in thread Duh. 'my' scope in if else blocks.
by gam3
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |