Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re^2: die in a DESTROY

by water (Deacon)
on Sep 27, 2005 at 19:19 UTC ( #495515=note: print w/ replies, xml ) Need Help??

in reply to Re: die in a DESTROY
in thread die in a DESTROY

 die is the same as  print STDERR "message"; exit(1) ???


Never knew that! Is in docs somewhere?

How does  print STDERR "message"; exit(1) work with eval then?


Comment on Re^2: die in a DESTROY
Select or Download Code
Replies are listed 'Best First'.
Re^3: die in a DESTROY
by sauoq (Abbot) on Sep 27, 2005 at 19:55 UTC
    die is the same as print STDERR "message"; exit(1) ???

    Well, it's not exactly the same. Specifically, the status you exit with shouldn't necessarily be 1 if you want a perfect emulation. But, the right status to exit with is easy enough to determine. See below.

    Never knew that! Is in docs somewhere?

    The first paragraph of the perlfunc entry for die states:

    die LIST Outside an "eval", prints the value of LIST to "STDERR" and exits with the current value of $! (errno). If $! is 0, exits with the value of "($? >> 8)" (backtick `command` status). If "($? >> 8)" is 0, exits with 255.

    How does print STDERR "message"; exit(1) work with eval then?

    Exactly like you would expect. Since exit doesn't care whether you are in an eval or not, it will work fine. It's only because die has special behavior inside an eval that you are running into problems.

    "My two cents aren't worth a dime.";

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (11)
As of 2016-04-29 15:56 GMT
Find Nodes?
    Voting Booth?
    :nehw tseb si esrever ni gnitirW

    Results (441 votes). Check out past polls.