Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Converting HoA into HoH

by BrowserUk (Patriarch)
on Oct 31, 2005 at 06:19 UTC ( [id://504167]=note: print w/replies, xml ) Need Help??


in reply to Converting HoA into AoH

Ths assumes that each array has an even number of elements.

my $HoH = { map{ $_ => { @{ $HoA->{$_} } } } keys %{ $HoA } };

Update: I completely misread that. Here's the correct version.

my $HoH = { map{ $_ => { map{ $_ => } @{ $HoA->{$_} } } } keys %{ $Ho +A } };

Update2: And still it was wrong. I think you have your answer now, so I'll shut up.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: Converting HoA into HoH
by neversaint (Deacon) on Oct 31, 2005 at 06:26 UTC
    Dear BrowserUk,
    Thanks a lot for the response. But your code above returns this only:
    $VAR1 = { 'flintstones' => { 'fred' => 'barney' }, 'jetsons' => { 'george' => 'jane' } };
    Please correct me if I'm wrong. And also the size of the array may not be even.

    ---
    neversaint and everlastingly indebted.......

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2024-04-20 04:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found