in reply to How do I make the garbage collector throw an exception when it fails to auto-close a filehandle?
When a function has special cleanup needs, use tilly's ReleaseAction.
use ReleaseAction qw( on_release ); sub something { ... open my $fh, ... my $closer = on_release { if (defined($fh) && defined(fileno($fh))) { close($fh) or die(...); } }; ... }
$closer holds a reference to $fh, so $closer will get destroyed before $fh. (Not necessarily true if they survive until global destruction.)
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: How do I make the garbage collector throw an exception when it fails to auto-close a filehandle?
by Aristotle (Chancellor) on Jan 13, 2007 at 07:37 UTC | |
by ikegami (Patriarch) on Jan 14, 2007 at 06:37 UTC |
In Section
Seekers of Perl Wisdom