Ok, this one has me entirely confused. Although I have a workaround (see below), the reason I even need a workaround escapes me.

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;"


In reply to can't assign signal handler an undef value by papidave

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.