Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^3: Catching errors in closing lexical filehandles

by graff (Chancellor)
on Sep 27, 2004 at 08:06 UTC ( #394096=note: print w/replies, xml ) Need Help??


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

Yes, what you say about low-level C-like behavior vs. DWIM Perl-like behavior is sensible. But you have to bear in mind that the "default, typical usage" model in Perl is to proceed as if the specifics of various error conditions don't usually matter and you should be able to carry on regardless -- i.e. in the "generic" case you ignore error conditions, and only attend to them (with an extra line or few of code) when you feel a specific need to do so.
  • Comment on Re^3: Catching errors in closing lexical filehandles

Replies are listed 'Best First'.
Re^4: Catching errors in closing lexical filehandles
by gaal (Parson) on Sep 27, 2004 at 09:19 UTC
    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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2020-05-31 04:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If programming languages were movie genres, Perl would be:















    Results (173 votes). Check out past polls.

    Notices?