Dear Monks,

I seek your enlightenment again!

How does one easily parse through a hash of hash of hash of arrays? I'd like to treat the first 3 hashes as menus and the last value will be an array of options.

while(<DATA>) { chomp; my ($one, $two, $three, $four) = split /\:/, $_; push @{$DATA->{$one}{$two}{$three}}, $four; } sub choice { my @a; my $x = 0; while (my ($key, $value) = each %$DATA) { print "$x - $key\n"; push @a, $key; $x++; } print "select : "; chomp(my $a = <STDIN>); my @b; my $c = 0; while (my ($key, $value) = each %{$$DATA{$a[$a]}}) { print "$c - $key\n"; push @b, $key; $c++; } print "select : "; chomp(my $b = <STDIN>); my @d; my $e = 0; while (my ($key, $value) = each %{$$DATA{$a[$a]}{$b[$b]}} ) { print "$e - $key\n"; push @d, $key; $e++; } print "select : "; chomp(my $new = <STDIN>); #PRINT SELECT ARRAY my @counter = 0; foreach(@{$$DATA{$a[$a]}{$b[$b]}{$d[$new]}}) { print "$counter - $_\n"; $counter++; } print "select : "; chomp(my $count = <STDIN>); #DO SOMETHING WITH $counter[$count] } __END__ category1:category2:category3:options categorya:categoryb:categoryc:more options categoryd:categorye:categoryf:even more options

In reply to Parsing through a menu hash. by yoda54

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.