in reply to shift on empty array in list context broken
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: shift on empty array in list context broken
by LanX (Saint) on Jul 16, 2019 at 02:07 UTC | |
by Don Coyote (Hermit) on Jul 16, 2019 at 12:29 UTC | |
by LanX (Saint) on Jul 16, 2019 at 13:25 UTC | |
by Don Coyote (Hermit) on Jul 16, 2019 at 14:25 UTC | |
by LanX (Saint) on Jul 16, 2019 at 17:21 UTC | |
|