From: Michael on
I need a construction like this:

foreach $a(...)
{
foreach $b(...)
{
foreach $c(...)
{
foreach $d(...)
{
$myval=$hash{$a}{$b}{$c}{$d};
...
}
}
}
}

How to do this? What should be in braces (...)?

--- news://freenews.netfront.net/ - complaints: news(a)netfront.net ---
From: Uri Guttman on
>>>>> "M" == Michael <a(a)a.com> writes:

M> I need a construction like this:
M> foreach $a(...)
M> {
M> foreach $b(...)
M> {
M> foreach $c(...)
M> {
M> foreach $d(...)
M> {
M> $myval=$hash{$a}{$b}{$c}{$d};
M> ...
M> }
M> }
M> }
M> }

M> How to do this? What should be in braces (...)?

read perldoc perldsc, perldoc perlreftut for how to do this. at each
loop you need to get the keys of the next lower level or get the hash
reference of the next lower level. those docs will help you figure out
what to do.

uri

--
Uri Guttman ------ uri(a)stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
From: Ben Morrow on

Quoth Michael <a(a)a.com>:
> I need a construction like this:
>
> foreach $a(...)
> {
> foreach $b(...)
> {
> foreach $c(...)
> {
> foreach $d(...)
> {
> $myval=$hash{$a}{$b}{$c}{$d};

This is messy, and gets worse as the hash gets deeper. I would use
something like Data::Walk instead.

Ben

From: Tad McClellan on
Michael <a(a)a.com> wrote:


Apply "Use Rule 1" from:

perldoc perlreftut


> I need a construction like this:
>
> foreach $a(...)

foreach my $a (keys %hash)

> {
> foreach $b(...)

foreach my $b (keys %{$hash{$a}})

> {
> foreach $c(...)

foreach my $c (keys %{$hash{$a}{$b}})

> {
> foreach $d(...)

foreach my $d (keys %{$hash{$a}{$b}{$c}})

> {
> $myval=$hash{$a}{$b}{$c}{$d};
> ...
> }
> }
> }
> }
>
> How to do this? What should be in braces (...)?


--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.
From: J�rgen Exner on
Michael <a(a)a.com> wrote:
>I need a construction like this:
>
>foreach $a(...)
>{
> foreach $b(...)
> {
> foreach $c(...)
> {
> foreach $d(...)
> {
> $myval=$hash{$a}{$b}{$c}{$d};
> ...
> }
> }
> }
>}
>
>How to do this? What should be in braces (...)?

Maybe something trivial like

keys %a
keys %b
keys %c
keys %d


jue