# single arg, used for simple and dirty sub foo { my $arg = shift; } # more flexible, I've been using this more frequently for complex subs sub bar { my ($arg1, $arg2, @optionals) = @_; } # I want more sophisticated argument handling for optional args, so I pass a hash reference containing all the arguments in predefined keys sub bletch { my $href = shift; # will warn me if $href->{hello_sub} is not defined print 'hi!' if $href->{hello_sub}; } #### # processes arguments passed to subroutine in hashref # returns hash sub sub_opts { my $href = shift; error("bad options hashref: $href") if ref($href) ne 'HASH'; # get all options to return if they exist my %hash = map {$_ => exists $href->{$_} ? $href->{$_} : 0} keys %{$href}; return %hash; } # implemented like: sub foobie { my %opts = sub_opts(shift); # won't warn me if $opts{hello_sub} doesn't exist, just treats it as false print 'hi!' if $opts{hello_sub}; }