I see this in examples everywhere:
sub foo {
$var = shift;
# do stuff
}
It took me awhile to figure out that $var becomes the first param sent to the subroutine; eg, if they do this:
foo('bar');
then $var equals 'bar'.
But why use shift instead of the more obvious
$var = $_[0];? It's both shorter and more obvious, and they bench test to the same speed. And since shift actually modifies @_ then it can confuse things down the road.
Is there another reason, or is it just a personal preference thing?