Is there a difference between Perl's shift versus assignment from @_ for subroutine parameters?
- by cowgod
Let us ignore for a moment Damian Conway's best practice of no more than three positional parameters for any given subroutine.
Is there any difference between the two examples below in regards to performance or functionality?
Using shift:
sub do_something_fantastical {
my $foo = shift;
my $bar = shift;
my $baz = shift;
my $qux = shift;
my $quux = shift;
my $corge = shift;
}
Using @_:
sub do_something_fantastical {
my ($foo, $bar, $baz, $qux, $quux, $corge) = @_;
}
Provided that both examples are the same in terms of performance and functionality, what do people think about one format over the other? Obviously the example using @_ is fewer lines of code, but isn't it more legible to use shift as shown in the other example? Opinions with good reasoning are welcome.