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
In reply to How do I push values onto an existing hash? by jaa
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |