Today I learned... #1: variable scoping in if-else blocks
2024-07-04
This block of code is valid Perl:
if (my $var1 = calc1()) {
say $var1;
} elsif (my $var2 = calc2()) {
say "$var1, $var2";
}
As you can see, $var1
, which is declared in the if
clause, is visible inside the elsif
clause too.
Perl never ceases to amaze me!
Comments
Write your comment: