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

Re: Catching errors in closing lexical filehandles

by FoxtrotUniform (Prior)
on Sep 27, 2004 at 05:33 UTC ( [id://394071]=note: print w/replies, xml ) Need Help??


in reply to Catching errors in closing lexical filehandles

But what about close? I mean, I know *when* it happens: when $fh goes out of scope. That's the point if this construct. But how does it happen, in terms of error catching? I almost always want to handle errors on close. How do I express that using this syntax? (Where do I hook up my "or die"?)

Honestly, I'd do it explicitly. Depending on scoping rules for resource management isn't exactly the most obvious WTDI, although the bare block does make the point pretty well. Putting in an explicit close $fh or die "close: $!"; lets everyone reading your code know that, yes, you have thought about it, and dealt with it as you saw fit -- that you didn't forget to do something clever if close failed.

(On the other hand, I've never actually had close fail. Not that that's an excuse for not checking a system call's return value, of course. :-)

--
F o x t r o t U n i f o r m
Found a typo in this node? /msg me
% man 3 strfry

Replies are listed 'Best First'.
Re^2: Catching errors in closing lexical filehandles
by gaal (Parson) on Sep 27, 2004 at 05:43 UTC
    On the other hand, I've never actually had close fail.
    It's more likely to happen when you're dealing with special files, e.g. pipes and sockets.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2024-06-15 18:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    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.