in reply to shift vs @_
Suppose you'd write a function like map, its first argument plays a very different role than the rest - which can be any length. Wouldn't it make sense to write:
Starting withsub my_map { my $special_thingy = shift; foreach my $item (@_) { apply($special_thingy, $item); } }
is a potentially costly operation, since you are copying everything else in @_ - and it is slightly different as you lose the aliasing. And writing:my ($special_thingy, @list_of_items) = @_;
orsub my_map { foreach my $item (@_[1 ..$#_]) { apply($_[0], $item); } }
is not something I fancy.sub my_map { for (my $i = 1; $i < @_; $i++) { apply($_[0], $_[$i]); } }
|
---|
In Section
Seekers of Perl Wisdom