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

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