Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
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: (6)
As of 2014-11-27 02:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (178 votes), past polls