Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

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]
[james28909]: thanks for the vid holli, i do like it. thanks for sharing :)
[holli]: gives me goosebumps every time I watch it
holli gotta grab some groceries before dawn. l8ters
[erix]: s/dawn/dusk/
[erix]: (you're welcome :P)
[james28909]: you know, i had a thought a few mnths back. what if this universe were just a puzzle, waiting for life to figure it out!
[james28909]: what if one day we are able to grab the curtain that is "spacetime" and pull it back to reveal <insert imagination here> pulling at levers and ropes xD
[holli]: like dorothy?
[james28909]: see ya later holli
[james28909]: yeah like wizard of oz lol. its just a joke though

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (15)
As of 2017-12-15 14:41 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (433 votes). Check out past polls.