[ABE.pm] Re: Printing an array

Faber Fedor faber at linuxnj.com
Tue Apr 26 06:04:45 PDT 2005


On 25/04/05 21:09 -0400, Ricardo SIGNES wrote:
> * 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, 

$ary_ref = = $dbh->selectall_arrayref($stmt);

where

       $stmt = "select rd.cusip, rd.$_->{weight}, fd.cap
                from table1 rd
                left join table2 fd
                on rd.cusip = fd.cusip
                and rd.realdate = fd.realdate
                where rd.realdate =\'$date\'
                and rd.$_->{weight} is not null";

Better? :-)

> and $a tells me nothing /and/ is usually used by blocks for
> sort.

I'm using $a the way I use $i in for loops; it's just a placeholder.

> 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.

Good, cuz' I really want to get rid of that crap.  Now, if I can figure
out how to access the data by name instead of subscript.

-- 
 
Regards,
 
Faber Fedor
President
Linux New Jersey, Inc.
908-320-0357
800-706-0701

http://www.linuxnj.com





More information about the ABE-pm mailing list