Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

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

Hi,

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
Re^2: Using 'Shift' in subroutine argument
by GrandFather (Cardinal) 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

    Prints:

    wibble

    Perl is environmentally friendly - it saves trees

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://648621]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2014-09-18 22:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (126 votes), past polls