Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

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

by Anonymous Monk
on Sep 27, 2004 at 15:53 UTC ( #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?

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2020-06-02 11:35 GMT
Find Nodes?
    Voting Booth?
    Do you really want to know if there is extraterrestrial life?

    Results (17 votes). Check out past polls.