jaa has asked for the wisdom of the Perl Monks concerning the following question:
I have read this question in the FAQ, and also looked through perldata.
I often use this for named parameters:
Now, what I would like to do is something like:sub abc { my %param = @_; for my $required qw( banana nut ) { die "missing: $required" unless defined $param{$required}; } # etc }
sub abc { # set up defaults my %param = ( apples => 'green', banana => 'yellow', ); # now override with any passed params %param = @_; for my $required qw( banana nut ) { die "missing: $required" unless defined $param{$required}; } # etc }
but the @_ assignment to %param trashes any existing values. I already know I can
my %passed = @_; (@param{ keys %passed }) = values %passed;
but is there a way to do it without an intermediate hash? i.e. straignt from @_? I want something like push that works on a hash?
Hope this makes sense! Thanks in advance,
Jeff
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How do I push values onto an existing hash?
by broquaint (Abbot) on Jul 10, 2003 at 10:27 UTC | |
|
Re: How do I push values onto an existing hash?
by Zaxo (Archbishop) on Jul 10, 2003 at 10:29 UTC | |
by jaa (Friar) on Jul 10, 2003 at 10:39 UTC |