my %handler; BEGIN { %handler = (
foo => sub { ref $_[0] eq 'ARRAY' or croak "foo key takes a hashre
+f"; ... },
bar => sub { $_[0] =~ /wibble$/ or croak "bar key must end with 'w
+ibble'"; ... },
) }
sub process_something {
my %arg = @_;
my @results;
while( my ( $elem, $param ) = each %arg ) {
push @results, $handler->{ $elem }->( $param );
}
}
croak will say the error was in process_something, when you really want it to be thrown for the where the call to process_something was.
Makeshifts last the longest.