On Fri, 2006-16-06 at 12:15 +0200, Paul Johnson wrote:
> On Tue, Jun 13, 2006 at 12:06:02PM -0700, Lawrence Statton wrote:
>
> > Charles Clarkson wrote:
> > > @{ %$hash_ref }{ keys %kv_pairs } = values %kv_pairs;
> >
> > You can excise a little of the snyactic sugar there
> >
> > @$hash_ref{keys %kv_pairs} = values %kv_pairs;
>
> %hash = (%hash, %kv_pairs);
>
> hmmm, tradeoffs ...
When I wrote the original subroutine, I wanted to avoid things like
this. After all, push can be replaced in a similar manner:
push @list, $item;
@list = (@list, $item);
However, you have inspired a new version:
# --------------------------------------
# hset %hash, ( $key => $value, ... );
# Augment the hash with the key-value pairs.
# WARNING: This subroutine overwrites the value of any key that
already
# exists.
sub hset (\%%) {
my $hash_ref = shift;
die "odd number of items in hash\n" if @_ % 2;
while( @_ ){
my $key = shift @_;
$hash_ref->{$key} = shift @_;
}
}
--
__END__
Just my 0.00000002 million dollars worth,
--- Shawn
"For the things we have to learn before we can do them, we learn by doing them."
Aristotle
* Perl tutorials at http://perlmonks.org/?node=Tutorials
* A searchable perldoc is at http://perldoc.perl.org/
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>