> (I did post this via perlbug and to perlbug@perl.org but both appear
> to have gone into a black hole)
>
> The following code:
>
> if (open(my $fh, "/etc/passwd")) {
> ...
> }
>
> Leaves the file open at the exit of the scope (in fact to the end of
> the program). But $fh is out of scope, meaning the file should be
> closed.
May be this is because condition part of 'if' is within outer scope?
I guess that this is done for convenience - that is people could easily
write similar to your construct.
unless (open my $fh, "....") {
die "couldn't open";
}
# which is similar to
open my $fh, "..." or die "....";
# use $fh here
BTW if (condition) {...} expands to condition && do {...};
BR,
Vadim.
Thread Previous
|
Thread Next