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


In reply to Re: clearer code by stephen
in thread clearer code by Simplicus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.