Prev: Posting Guidelines for comp.lang.perl.misc ($Revision: 1.9 $)
Next: FAQ 4.9 How can I output Roman numerals?
From: Michael on 27 Jul 2010 03:16 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 27 Jul 2010 03:27 >>>>> "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 27 Jul 2010 07:45 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 27 Jul 2010 08:43 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 27 Jul 2010 10:33 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
|
Next
|
Last
Pages: 1 2 3 Prev: Posting Guidelines for comp.lang.perl.misc ($Revision: 1.9 $) Next: FAQ 4.9 How can I output Roman numerals? |