A filehandle will bet closed when:
- It is formally closed with close
- When it goes out of scope which occurs:
- If it is localised to a block and you exit said block, provided no closure of course
- When the program exits everything goes out of scope.
Examples, no or die $! for clarity not form.
open F, $file;
close F;
# F is closed
{
open my $fh, $file;
}
# $fh is closed
open F, $file;
exit 0;
# program is gone and F is closed
# closure
{
my $fh;
sub append {
unless ( $fh ) { open $fh, $file }
}
}
# closure means $fh is not destroyed, $fh remains open until program e
+xit