# 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}; }