papidave has asked for the wisdom of the Perl Monks concerning the following question:
The requirement is to be able to allow users to interrupt a certain operation (Ctrl-C) which may be called from an application that has $SIG{INT} set to 'IGNORE'. The initial code for this (Perl 5.8.8, Linux) was:
my $intr = 0; my $save_handler = $SIG{INT}; $SIG{INT} = sub { $intr++ }; # do something here ... $SIG{INT} = $save_handler; # check value of $intr to see if I was interrupted...
What I found was that the code worked properly when $SIG{INT} had been blocked, but if called from code that did not alter $SIG{INT}, I got slammed with a "Use of uninitialized value in scalar assignment" warning.
Since I want my code to run clean, I did some investigation. First, the key INT exists, and has an undefined value. But I get the warning when I try to assign an undefined value back into the hash.
I can avoid the assignment by using a local $SIG{INT}, e.g.:
my $intr = 0; { local $SIG{INT}; $SIG{INT} = sub { $intr++ }; # do something here ... } # end of scope for local handler # check value of $intr to see if I was interrupted...
... but this seems entirely bogus. Can someone suggest a good reason why %SIG would be initialized with values that I can't assign to it? I don't get this warning when I do a simple "$foo{INT} = undef;"
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: can't assign signal handler an undef value
by shmem (Chancellor) on Dec 21, 2007 at 23:20 UTC | |
|
Re: can't assign signal handler an undef value
by sgifford (Prior) on Dec 22, 2007 at 05:46 UTC |