Quoth "Jochen Lehmeier said:
The difference is that "shift" is changing the array, while the assignment
does not.
So, if you're pedantic, you might ask why all those bytes have to be
shifted around just to get at the first argument.
All which bytes? shift on @_ is special-cased, since it's so common, to
do nothing more than adjust a pointer.
[snip]
Ben
Hey Ben. I'm not really sure but since Perl doesn't seem to give anything
back, adjusting the pointer would seem all it does on "shift,pop" .. and
"unshift,push,splice" if there is room to expand at the boundries without
needing more memory.
For example unshift grows down, push grows up, shift shrinks up, pop shrinks
down via head/tail pointers.
Of course, this is if internally, a Perl array is really an array of pointers
to structures with pointers to data grabbed from a free pool that is managed by Perl.
Its hard to fathom it could be done any other way with typless data (elements) but
I'm sure there is optimizations or some hybrid methods being used.
And within the array's current block of pointers, anything that can be moved
around without re-allocation is prefferable, say from using splice.
I don't know for sure, I'm sure there is some paper on implementing a typeless
language, but if shift @array did a re-alloc then move every time, or just a
move, then performance would really fall off.
-sln