in reply to Getting subroutine @_ w/ defaults
use Carp; sub example { my %options = ( 'DEBUG' => 0, 'TMPL_PATH' => undef ); my %args = ( %options, @_ ); foreach ( keys %args ) { croak( 'Unknown argument passed to subroutine - ', $_ ) unless exists $options{$_}; } . . }
This code makes use of a second hash for the definition of default values for arguments and incorporates a check for unknown arguments by comparing the keys of the merged hash %args with that of the default values (%options).
|
|---|