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

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
From the Camel Book -

The routine indicated by $SIG{__DIE__} is called when a fatal exception is about to be thrown. The error message is passed as the first argument. When a __DIE__ hook routine returns, the exception processing continues as it would have in the absence of the hook, unless the hookroutine itself exits via a goto, a loop exit, or a die. The __DIE__ handler is explicitly disabled during the call, so that you yourself can then call the real die from a __DIE__ handler. (If it weren't disabled, the handler would call itself recursively forever.) The case is similar for __WARN__.

When you call  die "something" the sub ref'ed in  $SIG{__DIE__} is called (you have an anonymous sub in your code). So the top-down approach is broken because your die called the subroutine with your die text as the first arg. If you modify your code to something like this, you will see what is going on -

#!/usr/bin/perl use strict; use warnings; local $SIG{'__DIE__'} = sub { (my $x = $_[0]) =~ s/foo/bar/g; print $x +; die $x; }; eval { die "foo lives here" }; print "got here\n";

Output

bar lives here at testme line 7. got here
As you can see foo changed to bar. Also the program prints got here becaue die was called from an eval block.

As an exercise try deleting eval (just the word from the above code) see what happens -

cheers

SK


In reply to Re: help in $SIG by sk
in thread help in $SIG by uva

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found