Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re: hash of hashes

by marinersk (Curate)
on Oct 06, 2013 at 03:43 UTC ( #1057107=note: print w/replies, xml ) Need Help??

in reply to hash of hashes

If it will help you, a sample of Hash of Hashes:
my %hash = (); $hash{'jeep'}{'wrangler'} = 1; $hash{'jeep'}{'liberty'} = 1; $hash{'ford'}{'pinto'} = 1; $hash{'ford'}{'taurus'} = 1;

You can use Data::Dumper to see what %hash looks like, and probably it will help you understand hash of hashes better.

Replies are listed 'Best First'.
Re^2: hash of hashes
by Anonymous Monk on Oct 06, 2013 at 03:57 UTC

    can you suggest the logic how can i handle this situation using hash of hashes

      You seem to be pretty much at sea on this, so here's a bit of an elaboration on marinersk's approach. I'm assuming you can read "statements" from a file, get rid of newlines (see chomp), write data to a file, etc.

      >perl -wMstrict -le "use Data::Dumper; ;; my @statements = ( 'strawberry red green rose', 'apple red rose', 'mango green', ); ;; my %hash; for my $statement (@statements) { my ($fruit, @colors) = split m{\s+}xms, $statement; for my $color (@colors) { $hash{$fruit}{$color} = 1; } } ;; print Dumper \%hash; " $VAR1 = { 'mango' => { 'green' => 1 }, 'strawberry' => { 'rose' => 1, 'green' => 1, 'red' => 1 }, 'apple' => { 'rose' => 1, 'red' => 1 } };

      See perldsc for a discussion of techniques for iterating through a data structure of this (hash-of-hashes, HoH) or any other kind. As others have said, we would be happy to answer further questions, but the community really likes to see supporting work as well.

      Update: Also see Re: hash of hashes for a different, perhaps more directly expressive data structure.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1057107]
[GotToBTru]: and it includes a reference number that I didnt recognize
[GotToBTru]: I had to dig into the code to find out where it came from .. and it makes no sense
[GotToBTru]: so I emailed my contact asking if we could just stop sending it .. I'm afraid she is going to ask "what is that anyway?"
[MidLifeXis]: heh.
[MidLifeXis]: Most likely it is a code that some undocumented system, hidden behind layers of IT, deep in the bowels of the building under the machine room floor, reads that code to keep a presence switch from going off. :-b
[MidLifeXis]: I think I forgot "running on a farm of commodore 64, vic 20s, trs 80s, and apple ]|[e systems"

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (9)
As of 2017-01-20 19:04 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (176 votes). Check out past polls.