Beefy Boxes and Bandwidth Generously Provided by pair Networks Russ
Just another Perl shrine
 
PerlMonks  

Turning Hash of Arrayrefs into Hash of Hashrefs

by merlyn (Sage)
on Jun 13, 2000 at 04:33 UTC ( #17824=note: print w/ replies, xml ) Need Help??


in reply to clarification...
in thread hash of lists - hash of hashes

In place, you could do something like this:

for (@HoL{keys %HoL}) { $_ = {map {$_, 1} @$_}; }
(You can use values in place of the slice in 5.6, but I'm not there yet.)

If you really need a copy, that's a little odder, like this:

%HoH = map { $_ => {map { $_, 1 } @{$HoL{$_}}} } keys %HoL;
Untested, but I think I got my indirections right.

-- Randal L. Schwartz, Perl hacker


Comment on Turning Hash of Arrayrefs into Hash of Hashrefs
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (8)
As of 2014-04-18 23:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (472 votes), past polls