The limit of if is encountered if you declare a variable.
if (!open(my $fh, '<', $qfn)) {
...
}
print $fh $s; # XXX
if (my ($y) = f($x)) { # Returns () on error.
...
}
print defined($y) ? $y : '[undef]'; # XXX
Solutions:
-
Declare the var earlier:
my $fh;
if (!open($fh, '<', $qfn)) {
...
}
my $y;
if (($y) = f($x)) { # Returns () on error.
...
}
-
Save the result:
my $success = open(my $fh, '<', $qfn);
if (!$success) {
...
}
my $success = my ($y) = f($x); # Returns () on error.
if (!$success) {
...
}
-
Use do:
open(my $fh, '<', $qfn)
or do { ...
};
my ($y) = f($x) # Returns () on error.
or do { ...
};
| [reply] [d/l] [select] |