in reply to Signals and 'IGNORE'

Although set $SIG{INT} to undef is perfectly right.

A more portable solution would be, to remember the value of $SIG{INT} before you set it to 'IGNORE', and restore the old value whenever you want it.

By doing this, you reduce your dependency on Perl's future behavior changes.

This is just about style.

Replies are listed 'Best First'.
Re: Re: Signals and 'IGNORE'
by bart (Canon) on Jan 07, 2003 at 11:38 UTC
    A more portable solution would be, to remember the value of $SIG{INT} before you set it to 'IGNORE', and restore the old value whenever you want it.
    That's precisely what local() is for.

    Over the years, people are so wrapped in the discussions of local vs. my, that they tend to forget what a great concept local really is. Unfortunately, it doesn't work on lexical scalars.

    my $foo; { local $foo; }
    Can't localize lexical variable $foo at ...
    Oddly enough, it does work on individual hash and array elements, even when those hashes and arrays are lexicals!
    my %hash = (a => 'one', b => 'two', c => 'three' ); use Data::Dumper; { local $hash{b} = 'Hello!'; print Dumper \%hash; } print Dumper \%hash;
    Unfortunately, if a localised hash element didn't exist in the outer scope, then when it's restored, it is merely set to undef, not deleted. So you end up with one hash element more than you had before. You can localise the entire hash — if it isn't a lexical, that is; but still...