----- Original Message ----- From: "William Martell" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> Sent: Monday, December 22, 2003 10:26 AM Subject: Read Fix Length Text, Loop Problems
> Hello All, > > Thanks for reading my email. I am trying to read a fix length text file and > extract specific substrings from each line. I would like to extract > specific things depending on which line is being read so I can avoid picking > up trash reading every line. The pattern repeats itself over and over again > until completion, so I think I should set a counter and then use the counter > to choose which set to extract, then I will reset the counter again to > repeat the process. I am having trouble understanding how to set the > counter and determine what line is being read to extract. > > Any help or hints would be greatly appreciated. > > Thanks Again and Merry Christmas. > Will Martell > Dallas Texas > > > PS. A sample of the data is attached for your review. > > Here is my code.-------------------------------------------#!/perl > > open (INFILE, "artb30_short.da4") || die "Can't open artb30.da4 file."; > > > > my @order_detail; > > @data = <INFILE>; > > foreach $row ( @data ){ > > if( $row == 1 ){ > > # extract fields for row 1 > my %item1 = ( > cust_number => substr( $line, 0, 6 ), > cust_name => substr( $line, 8, 31 ), > cycle => substr( $line, 40, 5 ), > customer_type => substr( $line, 47, 15 ), > acct_contact => substr( $line, 64, 20 ), > phone => substr( $line, 86, 15 ), > credit_limit => substr( $line, 104 ) > ); > > # trim spaces > while ( my ($key, $value) = each %item1 ) { > $value =~ s/^\s+//; #beginning spaces > $value =~ s/\s+$//; #ending spaces > } > > # save for later processing > push @order_detail, \%item1; > > } elsif ( $row = 2 ) { > > # extract fields for row 2 > my %item2 = ( > inv_no => substr( $line, 0, 6 ), > type => substr ( $line, 6, 3 ), > inv_date => substr( $line, 12, 3 ), > current => substr( $line, 23, 8 ), > days_1_30 => substr( $line, 36, 11 ), > days_31_60 => substr( $line, 51, 11 ), > days_61_90 => substr( $line, 64, 11 ), > days_over_90 => substr( $line, 78, 11 ), > on_hold => substr( $line, 92, 11 ), > unap_cash => substr( $line, 106, 11 ), > total_ar => substr( $line, 120, 11 ) > ); > > # trim spaces > while ( my ($key, $value) = each %item2 ) { > $value =~ s/^\s+//; #beginning spaces > $value =~ s/\s+$//; #ending spaces > } > > # save for later processing > push @order_detail, \%item2; > > > } else { > > # extract fields for row 3 > my %item3 = ( > cust_totals_current => substr( $line, 23, 8 ), > cust_totals_days_1_30 => substr( $line, 36, 11 ), > cust_totals_days_31_60 => substr( $line, 51, 11 ), > cust_totals_days_61_90 => substr( $line, 64, 11 ), > cust_totals_days_over_90 => substr( $line, 78, 11 ), > cust_totals_on_hold => substr( $line, 92, 11 ), > cust_totals_unap_cash => substr( $line, 106, 11 ), > cust_totals_total_ar => substr( $line, 120, 11 ) > ); > > # trim spaces > while ( my ($key, $value) = each %item3 ) { > $value =~ s/^\s+//; #beginning spaces > $value =~ s/\s+$//; #ending spaces > } > > # save for later processing > push @order_detail, \%item3; > > } > > } > > PSS. I would like to thank > Bill Luebkert > Randy Sims > Richard Morse > Chuck Charbeneau > > For all there help in the past. You guys are great, I really appreciate > your assistance. > > > > Merry Christmas!! >
19:36:36 XXXXXXXX PAGE: 1 FUNCTION: ARTB XXXXXXXXXXXXXXXXXXXX DATE: 12/17/2003 FROM: 000000 THRU: 999999 SORTED: CUSTOMER CLASS 1 =================================================================================================================================== CUSTOMER GROUP: CUSTOMER CLASS 1 = =================================================================================================================================== CUS ID CUSTOMER NAME CYCLE CUSTOMER TYPE ACCT CONTACT PHONE CREDIT LIMIT ------ ------------------------------ ----- --------------- -------------------- --------------- -------------- 003678 XXXXXXXXXXXXXXXXXXXXXXXXXXXX 1 OPEN ITEM 0.00 INV NO TYP INV DATE CURRENT 1-30 31-60 61-90 OVER 90 ON HOLD UNAP CASH* TOTAL A/R ------ --- -------- ----------- ----------- ----------- ----------- ----------- ----------- ----------- ----------- 054616 I 121703 603.73 603.73 CUSTOMER TOTALS ----------- ----------- ----------- ----------- ----------- ----------- ----------- ----------- 603.73 603.73 ----------------------------------------------------------------------------------------------------------------------------------- CUS ID CUSTOMER NAME CYCLE CUSTOMER TYPE ACCT CONTACT PHONE CREDIT LIMIT ------ ------------------------------ ----- --------------- -------------------- --------------- -------------- 003662 XXXXXXXXXXXXXXXXXXXXXXXXXXXXX 1 OPEN ITEM 0.00 INV NO TYP INV DATE CURRENT 1-30 31-60 61-90 OVER 90 ON HOLD UNAP CASH* TOTAL A/R ------ --- -------- ----------- ----------- ----------- ----------- ----------- ----------- ----------- ----------- 054601 I 121603 4,900.00 4,900.00 CUSTOMER TOTALS ----------- ----------- ----------- ----------- ----------- ----------- ----------- ----------- 4,900.00 4,900.00 ----------------------------------------------------------------------------------------------------------------------------------- =================================================================================================================================== GROUP TOTALS ----------- ----------- ----------- ----------- ----------- ----------- ----------- ----------- 5,503.73 5,503.73 PERCENTAGE OF TOTAL 100.00 100.00 =========== =========== =========== =========== =========== =========== =========== ===========
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>