Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: INIT {$SIG{__DIE__} and Getopt::Long

by fishmonger (Chaplain)
on Jul 29, 2015 at 18:44 UTC ( [id://1136781]=note: print w/replies, xml ) Need Help??


in reply to INIT {$SIG{__DIE__} and Getopt::Long

An alternative to using print STDERR "error message"; as sundialsvc4 suggested, you could do warn "error message"; which does the same thing.

Replies are listed 'Best First'.
Re^2: INIT {$SIG{__DIE__} and Getopt::Long
by afoken (Chancellor) on Jul 30, 2015 at 07:23 UTC
    An alternative to using print STDERR "error message"; as sundialsvc4 suggested, you could do warn "error message"; which does the same thing.

    Strictly speaking, no. They don't do the same.

    warn does more than just printing to STDERR. warn appends filename and line number to the text, unless the text ends with a newline. It also checks $SIG{__WARN__}. If a handler is set, the handler is called and nothing is printed by warn itself. This is documented in perlfunc.

    If you just want to print to the error output, use print STDERR. It does not modify the text, and it calls no handlers. If you need to warn that something is wrong, use warn.

    And if there is a fatal error, use die. Don't mess with warn, print STDERR and exit in that case, because only die errors can be caught by the caller using eval (or $SIG{__DIE__}).

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
    A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-04-24 05:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found