Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: You *Can* Catch errors in closing lexical filehandles

by Anonymous Monk
on Sep 27, 2004 at 15:53 UTC ( [id://394212]=note: print w/replies, xml ) Need Help??


in reply to You *Can* Catch errors in closing lexical filehandles
in thread Catching errors in closing lexical filehandles

eval would only "drop" something and populat $@ if something went wrong - that is, a "die" or a fatal error. But in the code you give, nothing goes wrong. Sure, print() and the implicite close() might return false values, but that doesn't mean the code dies. Hence, $@ will be undefined.

Beside that, I wouldn't use this construct. Sure, it might be safe in this simple case, but in general, you might have more code in the block. Which means that upon termination of the block, end-of-scope actions will be run. Lexical variables will go out of scope, DESTROY blocks might be run, and local variables will get their old values back. This might cause all kinds of library calls to happen, each of which might set $! (even if they succeed!)

  • Comment on Re: You *Can* Catch errors in closing lexical filehandles

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (2)
As of 2024-04-19 01:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found