S
SL_McManus
Hi All;
I am fairly new to Perl. I have a file with close to 3000 lines
that I would like to split out in a certain way. I would like to put
the record type starting in column 1 for 2 spaces, the employer code
in column 23 for 29 spaces and employer description in column 53 for
30 spaces. I have tried modifying an existing file with no real
success. I haven't found anything that specifically answers my
question. Any guidance would be appreciated.
My input file would look like this
09 A/B A & B Construction Co.
I'm working on a script so that I don't have to move all of these
manually. The code I am working on is the following. I didn't want to
delete anything, so that is why a good bit of it is commented out.
Thanks in Advance
my ($mday,$mon,$year) = (localtime(time))[3,4,5];
$year -= 100 ;
$mon++;
my $date = sprintf("%02d%02d%02d%02d","20",$year,$mon,$mday);
my @records = ( );
$infile .= '.' . $date;
open(INPUT, $infile) or die "Unable to open $infile: $!\n";
#@lines = <INPUT>; # reads in all lines when called like this
my $inrecord = 0;
my $i = -1; # $i++ the first time will make this 0
while(<INPUT>) {
#($a,$b,$c)=split(" ",$string);
$str=split(" ",split,3);
#my $a = substr(1, 2);
#my $b = substr(23, 29);
#my $c = substr(53, 29);
#print $str[0];
#print " ";
#print $str[1];
#print " ";
#print $str[2];
#print "\n";
}
close(INPUT);
my $record;
open(OFH, '>' . $outfile) or die $!;
for $record (@records) {
# split it up per-line
#for $line (split(/\r?\n/, $record)) {
#my $a = substr($line, 1, 2);
#my $b = substr($line, 23, 29);
#my $c = substr($line, 53, 29);
#print @records;
#print "TESTING!!! \n";
#print $a;
#print " ";
#print $string;
#print " ";
#print $c;
#print $line;
#print "\n";
#print $record;
#print "\n";
#print OFH $record;
#open(OFH, '>' . $outfile) or die $!;
# my $a = substr($a, 1, 2);
# my $b = substr($b, 23, 29);
# my $c = substr($c, 53, 29);
# print the whole $record to the outfile
# print OFH $a,$b,$c;
#}
}
# }
#}
close(OFH);
I am fairly new to Perl. I have a file with close to 3000 lines
that I would like to split out in a certain way. I would like to put
the record type starting in column 1 for 2 spaces, the employer code
in column 23 for 29 spaces and employer description in column 53 for
30 spaces. I have tried modifying an existing file with no real
success. I haven't found anything that specifically answers my
question. Any guidance would be appreciated.
My input file would look like this
09 A/B A & B Construction Co.
I'm working on a script so that I don't have to move all of these
manually. The code I am working on is the following. I didn't want to
delete anything, so that is why a good bit of it is commented out.
Thanks in Advance
my ($mday,$mon,$year) = (localtime(time))[3,4,5];
$year -= 100 ;
$mon++;
my $date = sprintf("%02d%02d%02d%02d","20",$year,$mon,$mday);
my @records = ( );
$infile .= '.' . $date;
open(INPUT, $infile) or die "Unable to open $infile: $!\n";
#@lines = <INPUT>; # reads in all lines when called like this
my $inrecord = 0;
my $i = -1; # $i++ the first time will make this 0
while(<INPUT>) {
#($a,$b,$c)=split(" ",$string);
$str=split(" ",split,3);
#my $a = substr(1, 2);
#my $b = substr(23, 29);
#my $c = substr(53, 29);
#print $str[0];
#print " ";
#print $str[1];
#print " ";
#print $str[2];
#print "\n";
}
close(INPUT);
my $record;
open(OFH, '>' . $outfile) or die $!;
for $record (@records) {
# split it up per-line
#for $line (split(/\r?\n/, $record)) {
#my $a = substr($line, 1, 2);
#my $b = substr($line, 23, 29);
#my $c = substr($line, 53, 29);
#print @records;
#print "TESTING!!! \n";
#print $a;
#print " ";
#print $string;
#print " ";
#print $c;
#print $line;
#print "\n";
#print $record;
#print "\n";
#print OFH $record;
#open(OFH, '>' . $outfile) or die $!;
# my $a = substr($a, 1, 2);
# my $b = substr($b, 23, 29);
# my $c = substr($c, 53, 29);
# print the whole $record to the outfile
# print OFH $a,$b,$c;
#}
}
# }
#}
close(OFH);