Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Using 'Shift' in subroutine argument

by sen (Hermit)
on Nov 02, 2007 at 10:54 UTC ( [id://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); 

Replies are listed 'Best First'.
Re^2: Using 'Shift' in subroutine argument
by GrandFather (Saint) 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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://648621]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2024-03-19 09:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found