Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

difference between shift and assignment

by vinoth.ree (Monsignor)
on Mar 05, 2009 at 05:56 UTC ( [id://748406]=perlquestion: print w/replies, xml ) Need Help??

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};

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://748406]
Approved by jdtoronto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-19 22:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found