I have a script that goes thru an input file (always named cpuf.rpt) and does some formatting on it. The problem is that the file is "formatted" already by some wannabe's old utility, so I have to unformat it first, then put it into the format I need for (my) generic reporting utility.
#!/usr/perl/bin -w
my @coswork_test;
my @func_test;
my $count = 0;
open (REPORT, "cpuf.rpt") || die "Can't open CPUF.RPT: $!\n";
open (OUTFILE, ">cpuf.med") || die "Can't open CPUF.OUT: $!\n";
while (<REPORT>) {
s/^ +//; #remove the leading whitespace;
s/\r//; #remove all carriage returns;
s/ +$//; #remove the trailing whitespace;
s/.+ : //; #remove the header information;
if ($_ =~ /\*+/) {
$_ =~ s/\*+//; #remove asterisk only rows;
$count++; #the asterisk line only happens once per recor
+d,
} #so we can use it to count records.
s/\n/³/;
if (($_ =~ /Cosmetics/)||($_ =~ /Function/)) { #look for _X_Pass or
+ _X_Fail
$_ =~ s/.+_X_(.{4}).*/$1/; #make it Pass or Fail
}
print OUTFILE "$_"; #print the line to the intermediate file.
}
close OUTFILE;
open (INFILE, "cpuf.med") || die "Can't open CPUF.MED $!\n";
open (OUTFILE, ">cpuf.out") || die "Can't open CPUF.OUT $!\n";
#now, print the headers:
print OUTFILE "DATE³QC SPEC.³REPAIR NUM³TECHNICIAN³CPU MODEL³CPU ASSET
+ NUM³COSMETICS ".
"WORKMANSHIP TEST³FUNCTIONALITY TEST³FAILURE DETAIL\n";
#and the information:
while (<INFILE>) {
s/.{129}//;
s/³{2}/\n/g;
#replace ³PassFail³ with ³Pass³Fail³, and Fail with Fail³³
s/³Fail³/³Fail³³/g;
s/³PassFail³/³Pass³Fail³/g;
s/Failure Detail - //g;
print OUTFILE "$_";
}
As you can see, it's a veritable feast of regex. What I would like to know is how I can combine some of these substitutions and create code that is (maybe) a bit more self documenting.
Two goals here - I'm a lazy typist and I don't want to forget what it was supposed to do when I come back to it in a year....
Simplicus