in reply to Catching errors in closing lexical filehandles
It's actually rather simple.
Of course, this is a global change, but that's life. You can make it regional by putting it inside a local setting:sub IO::Handle::DESTROY { my $deadbody = shift; not defined fileno $deadbody or close $deadbody or die "Cannot close $deadbody: $!"; }
The nested parens here ensure that the handle is destroyed before the local sub assignment goes out of scope.{ local *IO::Handle::DESTROY = sub { ... }; { open my $fh, "..."; ... } # will trigger here }
-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Catching errors in closing lexical filehandles
by gaal (Parson) on Sep 27, 2004 at 12:14 UTC | |
by merlyn (Sage) on Sep 27, 2004 at 12:44 UTC | |
by gaal (Parson) on Sep 27, 2004 at 13:39 UTC |
In Section
Seekers of Perl Wisdom