I prefer this:
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;
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...
BTW I hope you learned that using short-circuting conditionals as a control structure is a bad idea.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|