shift may not be the culprit, if you look at how the assignment is evaluated. Both the scalar and array assignment are evaluated in scalar context

DB<41> x { $max=100; while ( () = undef ) {print "$x, "; last if $ +max-- == 0 } } , , , , , , , , , , , , , , , ... , , , , , , , , , , , , , , , , , , +, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , + , , , , , , , , , , , empty array DB<42> x { $max=100; while ( $_ = undef ) {print "$x, "; last if $ma +x-- == 0 } } 0 undef

I dont know if this might be affecting how shift is working, but may shed some light.

I did investigate the splice/shift difference a little, they behave the same when both @x and @array are undef, but different when, as you highlighted they are empty.

Possibly shift and splice are optimised at that level due to their expected usage.

Update: this may be something to consider.

DB<60> x { $max=100; while ( @x = splice( @{[]},0,1 )) {print "$x, " +; last if $max-- == 0 } } 0 0 DB<61> x { $max=100; while ( @x = shift @{[]} ) {print "$x, "; last +if $max-- == 0 } } , , , , , , , , , , , , , , ... , , , , , , , , , , , , , , , , , , , +, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , + , , , , , , , empty array

In reply to Re: shift on empty array in list context broken by Don Coyote
in thread shift on empty array in list context broken by LanX

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.