Is there a difference between Perl's shift versus assignment from @_ for subroutine parameters?

Posted by cowgod on Stack Overflow See other posts from Stack Overflow or by cowgod
Published on 2009-01-06T02:58:38Z Indexed on 2010/04/23 23:23 UTC
Read the original article Hit count: 279

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.

© Stack Overflow or respective owner

Related posts about perl

Related posts about parameters