If you have a treatment for each line of the report you could also put them into an array of subs and then use the % operator to call them one by one:
use strict; use warnings; use Data::Dumper; my @subs; $subs[ 8 ] = sub { $_[0]->{'return1'} = substr $_[1], 0, 39 }; $subs[ 9 ] = sub { $_[0]->{'return2'} = substr $_[1], 0, 39 }; $subs[ 10 ] = sub { $_[0]->{'return3'} = substr $_[1], 0, 39 }; $subs[ 11 ] = sub { $_[0]->{'return4'} = substr $_[1], 0, 39 }; my @csv; while(<DATA>){ chomp; push @csv, {} if 1 == $. % 58; $subs[$. % 58]( $csv[-1], $_ ) if defined $subs[$. % 58]; } print Dumper \@csv; __DATA__ 06 01720168-00000000257980 123 S Somewhere HWY 192 172016-8 Company NATURAL GAS CO., INC. Business P O BOX 1547 123 Road Dr. Town ST 12345 SUITE# 1234 Town, ST 12345
Be aware, that the sub for the 58th line would be $subs[0]. If there is no action for a line, no sub needs to be specified.
This approach would only work if you really have a different approach for each line. If there are interactions between lines, then it probably cannot be fixed...
Update: fixed (removed) link to mod operator
In reply to Re: Parsing a Formatted Text File
by hdb
in thread Parsing a Formatted Text File
by Pharazon
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |