Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
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 imbibing at the Monastery: (10)
As of 2014-08-30 07:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (291 votes), past polls