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

Re: [FWP] Copying hashes



>>>>> "AL" == Andy Lester <andy@petdance.com> writes:

  AL> I'm using the following little snippet of code:
  AL>     my $r = $sth->fetchrow_hashref() or return 0;
  AL>     $self->{keys %$r} = $self->{values %$r};

  AL> I can't imagine there's a better way to plug the values from %$r into my
  AL> hash, but I figure it's worth asking about...

well if you call a correct method better, then there is a better way.

$self->{keys %$r} is a scalar expression with a list key. this will be
converted into the perl4 style multidimensional array by joining the
list elements with $; and using that as the single key to the anon hash.

you want true hash slices:

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

see my tutorial on them:

http://www.sysarch.com/perl/tutorials/hash_slices.txt

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com

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