I am trying to add the returned values from a hash to get the combined total value for the same key.
ID,Value
FB208025,1629.01
FB208025,1201.16
FB091027,1257.66
FB091027,741.92
FB135022,11210.66
FB135022,3238.67
FB135022,3569.34
FB135022,5534.23
I want to get total combined value for each ID:
FB135022=11210.66+3238.67+3569.34+5534.23
my %baldata;
while (defined($line = <IN>)) {
if ($line =~/caus/){
$ACTNUM = (split(/\t/,$line))[0];
$CSHBAL1 = (split(/\t/,$line))[17] ;
$baldata{$ACTNUM}{$CSHBAL1} = ($ACTNUM,$CSHBAL1);
$CSHBAL2 = $baldata{$ACTNUM}{$CSHBAL1};
print "$ACTNUM,$CSHBAL1,$CSHBAL2\n";
}
}
I can get the value for each KEYID everytime it appears, just can not
+figure out how to add the values up for each individual ID. Any help
+ will be appreciated.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.