eisenstein has asked for the wisdom of the Perl Monks concerning the following question:
Bad things:@a = (['a',1],['a',2],['b',3],['b',4]); # "db read" my $old; my $total = 0; # init foreach my $row (@a) { if ($old && $old ne $row->[0]) { print "$old: $total\n"; # finish row block $total = 0; # init } $total += $row->[1]; # processrow block $old = $row->[0]; # check variable } print "$old: $total\n"; # finish row block
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to loop over groups
by Juerd (Abbot) on Apr 02, 2002 at 08:07 UTC | |
by eisenstein (Acolyte) on Apr 02, 2002 at 08:19 UTC | |
by RMGir (Prior) on Apr 02, 2002 at 13:06 UTC | |
|
Re: How to loop over groups
by dragonchild (Archbishop) on Apr 02, 2002 at 16:20 UTC | |
|
Re: How to loop over groups
by YuckFoo (Abbot) on Apr 02, 2002 at 18:43 UTC |