perl.beginners
[Top] [All Lists]

Re: $SIG return to default

Subject: Re: $SIG return to default
From: Jeff Pang
Date: Fri, 26 Oct 2007 18:54:40 +0800
Newsgroups: perl.beginners

use local,like:


{  # in a code block
    local $SIG{__DIE__} = sub { ....};
    do something...
}

when code run out of the block,$SIG{__DIE__} will restore to its default value.

On 10/26/07, dolfantimmy <tim.sheets@xxxxxxxxx> wrote:
> I need to use $SIG to modify the behavior of die in a portion of my
> code.  The module I am calling uses die instead of returning a certain
> error, that I EXPECT to encounter.  So, I can do this....
> $SIG{_ _DIE_ _} = sub {
>     my $message = shift;
>
>     print STDOUT "Script died with this message:\n";
>     print STDOUT "$message\n";
> };
>
> However, I only want this modified behavior in one small section of
> the code.  How do I return the behavior to it's default?
>
> Thanks
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@xxxxxxxx
> For additional commands, e-mail: beginners-help@xxxxxxxx
> http://learn.perl.org/
>
>
>

<Prev in Thread] Current Thread [Next in Thread>