[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] Copying hashes



Quoting Andy Lester (andy@petdance.com):
> 
> I'm using the following little snippet of code:
>     my $r = $sth->fetchrow_hashref() or return 0;
>     $self->{keys %$r} = $self->{values %$r};
> 
> I can't imagine there's a better way to plug the values from %$r into my
> hash, but I figure it's worth asking about...

Well, a variation on yours that actually works (:-) is:

@{$self}{keys %r}=values %r;

you could try:

(%$self)=(%$self, %r);

which might be faster if %$self is small relative to %r (or might not).

Adam

-- 
Adam Rice -- wysiwyg@glympton.airtime.co.uk -- Blackburn, Lancashire, England

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe