in reply to Duh. 'my' scope in if else blocks.
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'"; }
|
---|