Slightly longer, but much more straightforward. (Although I did need the || 0 bits to make it quiet under warnings.) And, of course, all of the variables following a naming pattern suggests that you would be better off using a hash...my %total; while ( my $data = $t_sth->fetchrow_arrayref ) { my ( $amt, $id ) = @$data; $total{$id} += $amt / PRECISION; } $tcash += delete $total{$CASH} || 0; $taccount += delete $total{$ACCOUNT} || 0; $tcheck += delete $total{$CHECK} || 0; $tgift += delete $total{$GIFT} || 0; $tvoucher += delete $total{$VOUCHER} || 0; $tcc_man_auth += delete $total{$CC_MAN_AUTH} || 0; $tcredit += $_ foreach values %total;
BTW I hope you learned that using short-circuting conditionals as a control structure is a bad idea.
In reply to Re: Pop quiz: find the bug
by Anonymous Monk
in thread Pop quiz: find the bug
by Ovid
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |