vinoth.ree has asked for the wisdom of the Perl Monks concerning the following question:

Is there any difference between the two examples below in regards to performance or functionality?

Using shift:

sub function1 { my $varr1 = shift; my $varr2 = shift; }

Using @_

sub fun1{ my($varr1,$varr2)=@_; }

I know that the shift will modifies @_, and the assignment from @_ does not.

Replies are listed 'Best First'.
Re: difference between shift and assignment
by targetsmart (Curate) on Mar 05, 2009 at 06:56 UTC
    Is there any difference between the two examples below in regards to performance?
    use benchmark module and try to figure it out

    Is there any difference between the two examples below in regards to functionality?
    when you extract more variables from the argument the shift looks ugly, and (variables...) = @_ looks better. but it depends on context(area of use) too, because when you don't need all the variables passed as argument to be immediately extracted in the first statement inside the routine, then shift is suitable.(but you can use array slices also to achieve this).


    Vivek
    -- In accordance with the prarabdha of each, the One whose function it is to ordain makes each to act. What will not happen will never happen, whatever effort one may put forth. And what will happen will not fail to happen, however much one may seek to prevent it. This is certain. The part of wisdom therefore is to stay quiet.
Re: difference between shift and assignment
by cdarke (Prior) on Mar 05, 2009 at 09:53 UTC
Re: difference between shift and assignment
by jdtoronto (Prior) on Mar 05, 2009 at 06:03 UTC
    No.
Re: difference between shift and assignment
by puudeli (Pilgrim) on Mar 05, 2009 at 06:36 UTC

    No, from the shift docs

    If ARRAY is omitted, shifts the @_ array within the lexical scope of subroutines and formats, ...
    --
    seek $her, $from, $everywhere if exists $true{love};