in reply to hash of lists - hash of hashes

in case anyone wanted something to think about instead of other work, the original (extended) problem i want to solve was to suppose those lists contained other hash keys.. so now the problem is such:

%HoL = ( bob    => [ "mary", "ken"   ],
         aditya => [ "cary", "bob"   ],
         devil  => [ "bob", "aditya" ]
       );
and i then finally want:
%HoL = ( bob    => { mary => 1, ken => 1 },
         aditya => { cary => 1, bob => 1, mary => 1, ken => 1 },
         devil  => { bob => 1, mary => 1, ken => 1, aditya => 1, cary => 1 }
       )
so now everything shows itself readily when we use the hash, or something like that. and of course, one shouldn't get into a recursive loop, etc, blah blah blah

Replies are listed 'Best First'.
RE: extended problem
by merlyn (Sage) on Jun 13, 2000 at 05:06 UTC
    You posted the same question again. My code does that already. If you meant to convert a list-of-list-of-lists into a hash-of-hash-of-hashes (recursively), it's pretty straight forward.

    -- Randal L. Schwartz, Perl hacker

RE: extended problem
by Anonymous Monk on Jun 13, 2000 at 11:38 UTC
    this is actually what i finally came up with:

    my ($key, $value, $len); while (($key, $value) = each %HoL) { my $href = $HoL{$key} = { map {$_, 1} @$value }; do { $len = keys %$href; for (@HoL{@$value}) { if (ref eq "HASH" ) { @$href{keys %$_} = (1) x (keys %$ +_) } elsif (ref eq "ARRAY") { @$href{@$_} = (1) x @$_ } } $value = [ keys %$href ]; } while (@$value > $len); }
    it's iterative no less. any comments?
      on second run, this code is crack-headed. it ends up modifying the top level hash that it's iterating over and runs into bad stuff.
      note: that's me forgetting to login, up there posting..