Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Converting HoA into AoH

by pg (Canon)
on Oct 31, 2005 at 06:57 UTC ( #504180=note: print w/ replies, xml ) Need Help??


in reply to Converting HoA into AoH

use Data::Dumper; use strict; use warnings; my $HoA = { flintstones => [ "fred", "barney" ], jetsons => [ "george", "jane"], }; my $AoH; for my $flintstone (@{$HoA->{"flintstones"}}) { for my $jetson (@{$HoA->{"jetsons"}}) { push @$AoH, {"flintstones" => $ flintstone, "jetsons" => $jets +on}; } } print Dumper($AoH);


Comment on Re: Converting HoA into AoH
Download Code
Re^2: Converting HoA into AoH
by Moron (Curate) on Nov 01, 2005 at 12:59 UTC
    I am surprised no-one else complained yet, but this addresses only the example using hard coding, which cannot be useful to the OP given that the number of nesting levels of your loops translates to the number of families. It should be obvious that a solution should be generic to handle a variable number of set-of-sets of unpredisclosed group names each containing an unpredisclosed number of members each with unpredisclosed names.

    Update and I should have added that, Algorithm::Loops, which someone has already mentioned, handles precisely the situation where loop nesting level is variable, although I am personally more inclined towards the explicit recursion solutions that were also offered in response.

    -M

    Free your mind

      I am surprised no-one else complained yet
      It's out of courtesy, that nobody complained...

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (12)
As of 2014-09-19 14:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (140 votes), past polls