Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

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?

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (9)
As of 2015-11-30 11:47 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (769 votes), past polls