Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^5: join two hashes

by johngg (Canon)
on Jul 30, 2011 at 11:54 UTC ( [id://917614]=note: print w/replies, xml ) Need Help??


in reply to Re^4: join two hashes
in thread join two hashes

That's not an an error, that's what each value of the hash holds; a scalar reference to an anonymous array. Consider:-

knoppix@Microknoppix:~$ perl -E ' > %rep = ( one => 123, two => 456 ); > %comb = ( one => 987, two => 654 ); > %new = map { $_, [ $rep{ $_ }, $comb{ $_ } ] } keys %rep; > say qq{$_ => $new{ $_ } => @{ $new{ $_ } }} for keys %new;' one => ARRAY(0x81a1530) => 123 987 two => ARRAY(0x8195d00) => 456 654 knoppix@Microknoppix:~$

You have to de-reference the array reference (@{ $new{ $_ } } see perlreftut) to get at the contents.

Update: Added documentation reference.

Cheers,

JohnGG

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://917614]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2024-04-16 13:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found