drodinthe559 has asked for the wisdom of the Perl Monks concerning the following question:
#!/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>;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Sum fields in Array
by jethro (Monsignor) on Feb 04, 2010 at 20:26 UTC | |
by drodinthe559 (Monk) on Feb 04, 2010 at 20:56 UTC | |
by drodinthe559 (Monk) on Feb 04, 2010 at 21:01 UTC | |
by jethro (Monsignor) on Feb 04, 2010 at 21:24 UTC | |
|
Re: Sum fields in Array
by hangon (Deacon) on Feb 04, 2010 at 21:07 UTC | |
by drodinthe559 (Monk) on Feb 04, 2010 at 22:32 UTC |