Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: Using 'Shift' in subroutine argument

by sen (Hermit)
on Nov 02, 2007 at 10:54 UTC ( #648621=note: print w/replies, xml ) Need Help??

in reply to Using 'Shift' in subroutine argument


A subroutine's arguments come in via the special @_ array. The shift without an argument defaults to @_.

for example,

sub emp { 
  $name = shift; 
  $id = shift; 
  print "name, $name, id $id"; 
&emp('abc', 10); 
  • Comment on Re: Using 'Shift' in subroutine argument

Replies are listed 'Best First'.
Re^2: Using 'Shift' in subroutine argument
by GrandFather (Sage) on Nov 02, 2007 at 18:43 UTC
    The shift without an argument defaults to @_.

    except in main scope (outside a sub) where shift operates on @ARGV by default. Consider:

    perl -e "print shift" wibble



    Perl is environmentally friendly - it saves trees

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://648621]
[choroba]: It's just troll feeding.
[beech]: of course the magic word that explains everything :p
[erix]: they should lean to gnash their teeth a bit instead of writing more ^Re:NN-nodes :)
[erix]: *learn
[erix]: comic relief: how to start a riot and a fortune at the same time
[beech]: :) thats too generous to jdporter, don't start none won't be none -- there is about two decades (rounding up) worth of "ineffective" node titles -- leave the pope alone :p

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (8)
As of 2017-01-17 23:46 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (159 votes). Check out past polls.