either the code doesn't do what the documentation says

It does what the docs says. The documentation just glosses over details that turn out to be relevant when magic vars are involved. (Some people think this kind of abstraction is a good thing.)

The fact that my and local are treated as directives by the docs hindered my understanding of them when I started using Perl. They truly are functions (named operators), and the "initializer" assignment is unrelated to them.

By the way, my clears its argument variables whether an "initializer" is present or not as well, but since magic is removed too, there are no side-effects.

I only wish I could see how that informs the simpler case of:

They're identical to Perl. Perl doesn't have a concept of initializers. It sees a local, and it sees an assignment. It evaluates both independently.

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.

There isn't. There's a useful purpose for local $foo to set $foo to undef. In your statement, local $foo is being used for its side-effects, but it's primary function still occurs.

What you ask for requires local to check the optree to see if it's evaluated as the LHS of an assignment. I normally abhore anything that peeks at the optree to determine behaviour. Such code is inherently fragile. It works most of the time, leading people to think it always works, leading to subtle bugs. That makes the situation worse.

But in this case, we're already in that situation. So maybe it is appropriate here.

[Using POSIX to block the signal during the local] turns out to be essential in order to use local to automatically restore the $SIG state on forced exit (die) from an eval.

Not so. I already provided code that doesn't use POSIX or local and restores the signal automatically on scope exit.


In reply to Re^7: Setting signal handlers considered unsafe? by ikegami
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.