yoda54 has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Parsing through a menu hash.
by holli (Abbot) on Sep 06, 2005 at 08:36 UTC | |
by polettix (Vicar) on Sep 06, 2005 at 20:14 UTC | |
|
Re: Parsing through a menu hash.
by TedPride (Priest) on Sep 06, 2005 at 09:23 UTC |