[ABE.pm] Printing an array
Ricardo SIGNES
rjbs-perl-abe at lists.manxome.org
Mon Apr 25 18:09:44 PDT 2005
* Faber Fedor <faber at linuxnj.com> [2005-04-25T12:33:32]
> foreach $a (@{$ary_ref}) {
> $sum += $a->[1];
> # let our data struct be:
> # decile, cusip, weight, sum
> push(@deciles, (1, $a->[0], $a->[1], $sum)) if $sum <= 10.0;
> push(@deciles, (9, $a->[0], $a->[1], $sum)) if $sum <= 90.0and $sum > 80;
> push(@deciles, (10, $a->[0], $a->[1], $sum)) if $sum <= 100.0and $sum > 90;
>
> }
>
> (If anyone has a more elegant way of generating deciles or a better data
> structure, let me know).
Your choice of variable names is unfortunate. $ary_ref tells me nearly
nothing, and $a tells me nothing /and/ is usually used by blocks for
sort.
A minimal improvement might read:
for my $datum (@$data) {
$sum += $datum->[1];
push @results, [ int($sum / 10), $a->[0], $a->[1], $sum ];
}
At least that gets rid of all the C<< if $sum <= y and $sum > z >> crap.
--
rjbs
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://mail.pm.org/pipermail/abe-pm/attachments/20050425/38cdfc2f/attachment.bin
More information about the ABE-pm
mailing list