From: michael20545 on
27.07.2010 19:43, Tad McClellan пишет:
> 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 (...)?
>
>

Thank you!

--- news://freenews.netfront.net/ - complaints: news(a)netfront.net ---
From: Peter J. Holzer on
On 2010-07-27 14:33, J�rgen Exner <jurgenex(a)hotmail.com> wrote:
> Michael <a(a)a.com> wrote:
>>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

Maybe. But where do %a, %b, %c and %d come from?

hp

From: sln on
On Tue, 27 Jul 2010 21:58:20 +0700, michael20545 <a(a)a.com> wrote:

>27.07.2010 19:43, Tad McClellan ?????:
>> 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 (...)?
>>
>>
>
>Thank you!
>
>--- news://freenews.netfront.net/ - complaints: news(a)netfront.net ---

Make sure you read the docs because it gets even more nasty.
-sln

--------------------
use strict;
use warnings;

my %hash = (
av1 => 'av-1',
av2 => {
bv1 => 'bv-1',
bv2 => {
cv1 => 'cv-1',
cv2 => {
dv1 => 'dv-1',
dv2 => 'dv-2',
dv3 => 'dv-3',
},
cv3 => ['foo3','bar3'],
},
bv3 => 'bv-3',
},
av3 => 'av-3',
av4 => sub {print "av4\n"}
);

foreach my $a (keys %hash)
{
if (ref($hash{$a}) eq "HASH") {
foreach my $b (keys %{$hash{$a}})
{
if (ref($hash{$a}{$b}) eq "HASH") {
foreach my $c (keys %{$hash{$a}{$b}})
{
if (ref($hash{$a}{$b}{$c}) eq "HASH") {
foreach my $d (keys %{$hash{$a}{$b}{$c}})
{
my $myval=$hash{$a}{$b}{$c}{$d};
print "$d = $myval\n";
}
}
}
}
}
}
}

From: J�rgen Exner on
"Peter J. Holzer" <hjp-usenet2(a)hjp.at> wrote:
>On 2010-07-27 14:33, J�rgen Exner <jurgenex(a)hotmail.com> wrote:
>> Michael <a(a)a.com> wrote:
>>>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
>
>Maybe. But where do %a, %b, %c and %d come from?

Maybe from
%a = %hash
%b = $a{$a}
%c = $b{$b}
%d=$c{$c}

jue
From: John W. Krahn on
Michael 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 (...)?

foreach my $a ( values %hash ) {
foreach my $b ( values %$a ) {
foreach my $c ( values %$b ) {
foreach my $d ( values %$c ) {
$myval = $d;
}
}
}
}




John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction. -- Albert Einstein