Function arguments in Perl

a.k.a. URGHHH...

The three ways you want to remember are:

  1. If you don't know exactly what's coming, roll it all in a hash:

    sub perlFunc {
      my %args = @_;
      print $args{what_was_that_again};
    
      return(%args);
    }
    
  2. Or, if you do know what's coming:

    sub otherPerlFunc {
      my ($what_was_that_again, $oh_yeah, $never_mind) = @_;
    }
    
  3. And finally, if it's a single parameter you might as well just:

    sub oneMorePerlFunc {
      my $singleValue = shift;
    }
    

Posted 03 Aug 2007, tagged with perl