Gurus: I trying to figure out what is the best way to sum up a set of records that's in array. Should I reset the variables after it loops through to the next record? If so, how? Now, I'll need group the items that I want to generate individual PDFs for. I was thinking about dumping it out into a text file or database, so I can run a SQL query to sum up each category. Your help will be appreciated.
#!/usr/bin/perl -w use strict; use warnings; open PM, "C:/REPORT" or die "Couldn't open Report file: $!"; my (@fields,$systime,$company,$company_prev,$batch_num,$effent_date,$e +ntry_desc,$date_crt,$load_num,$eofbatch,$credits,$debits,$comp_ident, $total, $total_items); $batch_num = 0; while (my $pimrpt = <PM>) { next if ($pimrpt =~ m/^(\s)*$/ || $pimrpt =~ m/^(\*)/ || substr($p +imrpt,9,10) =~ m/SETTLEMENT/ || substr($pimrpt,12,6) =~ m/NUMBER/ || substr($pimrpt,8,9) =~ m/\d{9}/); #Skips over blank lines +. next unless (substr($pimrpt, 0, 8) =~ m/COMPANY/ || substr($pimrpt, 27, 12) =~ m/BATCH NUMBER/ || substr($pimrpt, 51, 12) =~ m/DATE CREATED/ || substr($pimrpt, 79, 17) =~ m/ENTRY DESCRIPTION/ || substr($pimrpt,0,7) eq $batch_num); if (substr($pimrpt, 0, 8) =~ m/COMPANY/) { $company = substr($pimrpt, 9, 18); }; if (substr($pimrpt, 27, 12) =~ m/BATCH NUMBER/) { $batch_num = substr($pimrpt, 42, 7); $effent_date = substr($pimrpt, 69, 8); $comp_ident = substr($pimrpt, 102, 9); }; if (substr($pimrpt, 79, 17) =~ m/ENTRY DESCRIPTION/) { $entry_desc = substr($pimrpt, 101, 13); }; if (substr($pimrpt, 51, 12) =~ m/DATE CREATED/) { $date_crt = substr($pimrpt, 69, 8); $load_num = substr($pimrpt, 107, 4) }; if (substr($pimrpt,0,7) eq $batch_num) { $total_items = substr($pimrpt, 8,16); $debits = substr($pimrpt, 24, 20); $credits = substr($pimrpt, 44, 20); push @fields, {company_ident => $comp_ident, company => $company, batch_number => $batch_num, effective_date => $effent_date, entry_description => $entry_desc, date_created => $date_crt, load_number => $load_num, debits => $debits, credits => $credits}; }; }; foreach my $x (@fields) { print $x->{company_ident} . "\t" . $x->{company} . "\t" . $x->{b +atch_number} . "\t" . $x->{effective_date} . "\t" . $x->{date_created} . "\t" . $x->{load_number} . "\t" . $x- +>{debits} . "\t" . $x->{credits} . "\n"; } print "Press Return to Conintue..."; my $x = <STDIN>;

In reply to Sum fields in Array by drodinthe559

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.