--- "A. Pagaltzis" <[EMAIL PROTECTED]> wrote:
> I donât know if this is just a silly example, but Iâm not sure it
> makes sense⦠why `die if extra_keys` when youâve already made
> sure that the set of keys can only be exactly @some_keys?
Oops. That was silly of me. Just another example of why I shouldn't
be retyping this :)
My first line should have been something like:
croak $error
unless @required == grep {exists $args->{$_}} @required;
> The code I use for such occasions is
>
> sub foo {
> my ( $args ) = @_;
> my %default = ( foo => 1, bar => 1, baz => 'quux' );
> my @optional_keys = qw( wibble wobble );
> my %args = ( %default, map {
> exists $args->{ $_ } ? ( $_ => delete $args->{ $_ } ) :
> ()
> } keys %default, @optional_keys;
> croak "I have no idea what you mean by @{[ keys %$args ]}" if
> %$args;
> # ...
> }
Yes, but you're altering the hash passed in by reference.
Cheers,
Ovid
--
If this message is a response to a question on a mailing list, please send
follow up questions to the list.
Web Programming with Perl -- http://users.easystreet.com/ovid/cgi_course/