I agree. The docs are misleading.

OK, so we're agreed: either the code doesn't do what the documentation says, or vice versa -- a bug in one or the other, by any reasonable standard, IMO :-)

Not so. I rely on that feature all the time.

Now I'm fascinated. I confess, I've tried, but I cannot imagine a useful purpose for the fact that  local $foo = 76 ; fleetingly sets $foo to undef, before setting it to the required 76.

I understand that  local $fred ; sets $fred to undef. As far as I can see your code fragment:

sub d :lvalue { print("$_[0]: ", defined($_[1]) ? "[$_[1]]" : "undef", "\n"); $_[1] } our $fred = 78; d("post assign", d("post local", local $fred) = 90);
performs a local $fred (setting it undef) and passes that to sub d where it, eventually gets treated/returned as an lvalue. So far, so interesting. I only wish I could see how that informs the simpler case of:
our $fred = 78 ; local $fred = 'ho hum' ;
where there is a straightforward initialiser and, AFAICS, no urgent need to set $fred to undef immediately before setting it to 'ho hum'.

Remembering, that the point here is that the current behaviour means that the recommended use of local for $SIG creates a very nasty hiatus in which the SIG_DFL state is set.

One can, of course, ignore the standard advice and save and restore the $SIG state by hand. Or get out POSIX and block the signal during the local. This second turns out to be essential in order to use local to automatically restore the $SIG state on forced exit (die) from an eval.


In reply to Re^6: Setting signal handlers considered unsafe? by gone2015
in thread Setting signal handlers considered unsafe? by gnosek

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.