Help for this page

Select Code to Download


  1. or download this
    foo(1,2,3,4);
    
    sub foo {
      my (@args) = @_; # now @args holds a _copy_ of all the arguments
    }
    
  2. or download this
    sub foo {
      my $first = shift; # get the first argument and remove it from @_;
      my $last  = pop;   # get the last argument and remove it from @_;
    }
    
  3. or download this
    my $i = 1;
    inc($i);
    sub inc {
      $i++;  #note: $i is not declared and read from @_
    }
    
  4. or download this
    my $i = 1;
    inc($i);
    ...
      my $i = shift;  # declare and read $i from @_
      $i++;
    }