Hi All, I am stuggling with creating a script that will take the value from a field on each line where the account number is the same and add them together. There will never be more than two lines per account number. End result would be to take the value in field 5 where acct# number is the same and print out 1 new line for each Acct# with the combined value. I can get the acct#, cusip and values. Just cant seem to figure out how to add them together. Any help will be greatly appreciated. Changed code a bit, problem I get now is $recs{$ACTNUM} += $CSH_TRD_BAL2 ; increments. Even if Actnum only exist once the value is incorrect. I want to get print out the actnum once with the combined value of $CSH_TRD_BAL2 for a single account number: ACTNUM,VALUE
my %recs =(); while (<inData>) { chomp; $line = $_; next unless ($line =~/^DTL/); $CUSIP = substr $line, 4, 12; $CUSIP =~s/\s+//g; $ACTNUM = substr $line, 240, 9; $CSH_TRD_BAL = substr $line, 64, 17; $CSH_TRD_BAL2 = substr $line, 64, 17; $recs{$ACTNUM} += $CSH_TRD_BAL2 ; &GetCusip("$CUSIP"); print "$recs{$ACTNUM} $CSH_TRD_BAL2 $CUSIP $ACTNUM\n " if ($CUSCOD +E eq 'MMKS'); }

In reply to combining values from multiple lines by mmittiga17

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.