http://qs321.pair.com?node_id=376757


in reply to When do filehandles close?

A filehandle will bet closed when:

  1. It is formally closed with close
  2. When it goes out of scope which occurs:
    1. If it is localised to a block and you exit said block, provided no closure of course
    2. 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

cheers

tachyon