LanX has asked for the wisdom of the Perl Monks concerning the following question:
Shouldn't shift behave like one element splice
DB<16> @array =() DB<17> (@x) = splice @array,0,1 DB<18> x @x empty array DB<19> (@x) = shift @array DB<20> x @x 0 undef # WTF
please note how loops over shift can't handle false values in scalar context, but become endless in list context.
This behaviour breaks conventions of other iterators ...
DB<1> @x = (1..3,0,undef,1..3) DB<2> $max=100 DB<3> while (my ($x) = shift @x) { print "$x,"; last if $max-- < 0 } 1,2,3,0,,1,2,3,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, DB<4> @x = (1..3,0,undef,1..3) DB<5> while (my $x = shift @x) { print "$x," } 1,2,3,
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
FootballPerl is like chess, only without the dice
|
|---|