in reply to clearer code
I was dreaming when I wrote this, forgive me if it goes astray...
All in all, it's a pretty clear piece of code as is. If I were a contractor assigned to it as legacy code, I would be very thankful and think nice thoughts about the coder that wrote it.
Couple of things you could do:
So, here's your first input loop, rewritten as I've suggested:
while (<REPORT>) { $_ = clean_line($_); if ($_ =~ /\*+/) { $_ =~ s/\*+//; #remove asterisk only rows; $count++; #the asterisk line only happens once per reco +rd, } #so we can use it to count records. if (($_ =~ /Cosmetics/)||($_ =~ /Function/)) { #look for _X_Pass o +r _X_Fail $_ =~ s/.+_X_(.{4}).*/$1/; #make it Pass or Fail } print OUTFILE "$_"; #print the line to the intermediate file. } ## ## clean_line() ## ## Argument: $line (string) - Line from the file that needs cleaning ## ## Returns: string - cleaned-up line ## ## Clean_line() returns the $line minus leading and ## trailing whitespace, headers, etc. ## sub clean_line { my $line = shift; #remove the leading and trailing whitespace $line =~ s/^\s*(.*?)\s*$/$1/; tr/\n\r³//; #remove all carriage returns; s/.+ : //; #remove the header information; }
Something like that... my brain isn't running. Also, you could consider reading the input file record-at-a-time by setting the input record separator to '*' x (whatever number of stars they put in the input file) . "\n". Then you wouldn't need to watch for the star-lines and count them separately. You might need to modify your regexps to deal with that though.
stephen
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: Re: clearer code
by Simplicus (Monk) on Apr 19, 2000 at 16:50 UTC |