From: Peter J. Holzer on
On 2010-07-28 00:36, J�rgen Exner <jurgenex(a)hotmail.com> wrote:
> "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(...)
>>>> {
[...]
>>>> }
>>>>}
>>>>
>>>>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}

Make that

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

and it will actually work.

Please make some effort to ensure that your postings are correct and
include all the relevant information. Especially since you are extremely
literal-minded and unwilling to "read between the lines" when it comes
to other people's postings.

hp
From: Ben Morrow on

Quoth "Peter J. Holzer" <hjp-usenet2(a)hjp.at>:
> On 2010-07-28 00:36, J�rgen Exner <jurgenex(a)hotmail.com> wrote:
> > "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(...)
> >>>> {
> [...]
> >>>> }
> >>>>}
> >>>>
> >>>>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}
>
> Make that
>
> %a = %hash
> %b = %{ $a{$a} }
> %c = %{ $b{$b} }
> %d = %{ $c{$c} }
>
> and it will actually work.

For some value of 'work', depending on what the for loop does in the
end. Much better would be

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

but that's really ugly at the bottom; better still would be

while (my ($a, $ah) = each %hash) {
while (my ($b, $bh) = each %$bh) {

Just use a module.

Ben

From: sln on
On Tue, 27 Jul 2010 22:30:23 -0700, "John W. Krahn" <jwkrahn(a)example.com> wrote:

>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 ) {
^
and if $a isin't a hash reference ?

> foreach my $b ( values %$a ) {

-sln
From: J�rgen Exner on
"Peter J. Holzer" <hjp-usenet2(a)hjp.at> wrote:
>Please make some effort to ensure that your postings are correct and
>include all the relevant information.

Why? After all I can be certain that _YOU_ will never fail to correct
any sloppyness on my part.

jue
From: Peter J. Holzer on
On 2010-07-28 13:34, J�rgen Exner <jurgenex(a)hotmail.com> wrote:
> "Peter J. Holzer" <hjp-usenet2(a)hjp.at> wrote:
>>Please make some effort to ensure that your postings are correct and
>>include all the relevant information.
>
> Why?

If the answer to that isn't obvious ...

> After all I can be certain that _YOU_ will never fail to correct any
> sloppyness on my part.

Don't be too sure. I do that only in some cases and the frequency is
decreasing.

hp