Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Handing back $SIG{__DIE__} under -w causes a warning?

by graq (Curate)
on Jun 04, 2004 at 14:39 UTC ( [id://360911]=perlquestion: print w/replies, xml ) Need Help??

graq has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to build a module that will handle all our perl in a nice way, along the way I have trapped $SIG{__DIE__}. After doing my thing, I want to hand it back, but I get an "Use of uninitialized value in scalar assignment at Hps.pm" error.

The Package:

package Hps; my $origHandler = $SIG{__DIE__}; $SIG{__DIE__} = 'Hps::grimReaper' unless ($^D); sub grimReaper { # We can drop out early if $^S is set because that means we're in +an eval die (@_) if (not defined $^S or ($] >= 5.005 and defined $^S and $^S)); # .. do some stuff .. # It is this line that causes an error. $SIG{__DIE__} = $origHandler; die "@_"; }
The script:
#!/usr/bin/perl -w use strict; use Hps; die ("Oh no!");
Is this a feature of the -w switch, or can I do this in a nicer way? Server Error (Error ID 1274635c2136032)

An error has occurred. The site administrators have been notified of the problem and will likely soon fix it. We thank you, for you're patients.

Replies are listed 'Best First'.
Re: Handing back $SIG{__DIE__} under -w causes a warning?
by dave_the_m (Monsignor) on Jun 04, 2004 at 14:57 UTC
    You can get this with the simple program like the following:
    perl -we '$SIG{__DIE__} = undef'
    Basically you aren't allowed to assign undef values to %SIG slots. Instead you need something like:
    $SIG{__DIE__} = defined $origHandler ? origHandler : 'DEFAULT'
    Although arguably Perl ought to be smart enough to DWIM. I might fix this.

    Dave.

Re: Handing back $SIG{__DIE__} under -w causes a warning?
by Abigail-II (Bishop) on Jun 04, 2004 at 15:01 UTC
    Next time, please indicate which line is giving the warning - that helps the people willing to help you.

    Having said that, I've no idea why this is giving a warning. It's actually the $SIG {__DIE__} that's giving the problems - setting it to something that's undefined seems to cause the warning. Smells like a bug to me.

    Abigail

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2024-03-29 15:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found