I would say it's because of three things:

1) $_ is often treated as a default argument to a function, for example for chop and as a default second argument for split. This in no way implies it should be a default LHS to an omitted assignment, just because shift takes an array argument rather than a scalar.

2) shift does have a default argument, @_, because it takes an array argument rather than a scalar.

3) using $_ as a default argument is a reasonably safe implementation, because it is applied only when the relevant argument is explicitly omitted from an actual function call; in other words is free from ambiguous meaning (including in a DWIM sense). But the intended meaning for an omitted assignment to a function call is that its return value is available for direct evaluation (e.g. MyFunc(shift())), which may be delayed to the next statement for some cases, but either way is never assigned to $_. So the precedent is in fact never to do what is suggested in the OP.

3) (conclusion) the proposed implementation is unsafe because $_ is intended to preserve its contents across scope and context boundaries, unless explicity assigned otherwise (omission of required arguments being deemed explicit enough), including for functions. The implementation proposed in the OP would therefore destroy the main purpose of $_.

One world, one people


In reply to Re: shift doesn't DWIM by anonymized user 468275
in thread shift doesn't DWIM by GrandFather

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.