Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re^4: Catching errors in closing lexical filehandles

by gaal (Parson)
on Sep 27, 2004 at 09:19 UTC ( [id://394103]=note: print w/replies, xml ) Need Help??

in reply to Re^3: Catching errors in closing lexical filehandles
in thread Catching errors in closing lexical filehandles

Fine, which is why I'm okay with a declarative syntax for turning on the error handling (that is off by default). It can be something like %SIG, or come to thing of it, pragmatic behavior lexically defined.
use closefail qw(:standard); use closefail { die "I'm not feeling so well: $!" };
There are plenty of ways this could be improved, I'm sure. for one thing, the naming is just the first thing that came to mind.

One possible complication in implementing this, however, is that the scope of this declaration needs to include the closing of the current scope, if you pardon the pun. So you can say this:

{ use closefail; open my $thing, $what or die "..."; # ... } # <- still in effect as this block ends
Instead of:
{ use closefail; { open my $thing, $what or die "..."; # ... } }

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://394103]
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-06-15 03:15 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.