Next: if/else and ternary operators
Up: if() { } and
Previous: if() { } and
Contents
Index
Variable scoping
Just as with loops, there are important aspects to
variable scoping that one should be familiar
with for conditional statements. As an example,
use strict;
my $amount_owed = 0;
my $status;
if ($amount_owed <= 0) {
$status = 'good';
}
print qq{The status is $status\n};
will run under use strict;, but
use strict;
my $amount_owed = 0;
if ($amount_owed <= 0) {
my $status = 'good';
}
print qq{The status is $status\n};
will not, because $status will only be defined
within the if() { } block, and thus is not
defined within the print statement.