in reply to clearer code

Hmm, it's not bad as it is. Here are some things I would do differently:
while (<REPORT>) { s/^\s+//; # get rid of leading whitespace s/\s+$//; # get rid of trailing whitespace tr/\r//d; # get rid of carriage returns the quick way tr/\n/³/; # superscript 3? I don't get it. s/.+ : //; # get rid of headers if (s/^\*+$//) { $count++; } # get rid of all asterisk rows, one for each record if (/(Cosmetics|Function)/) { s/.+_X_(Pass|Fail).*/$1/; # remove all but Pass or Fail }
and the other section looks about as compact as possible. I don't really see the point of s/.{129}//, though (it's not anchored, and 129 is an odd number). Perhaps substr would be more efficient. On second thought, you could do something like this:
s/Failure Detail - //g; # must come before next regexp s/³(Pass|Fail)/³$1³/; # Pass -> Pass³, Fail³ -> Fail³³ (implied :)
That depends on some assumptions about your dataset, notably that there are no instances of "Fail" which don't meet the search criteria.

Replies are listed 'Best First'.
RE: RE: clearer code
by Simplicus (Monk) on Apr 19, 2000 at 16:45 UTC
    the s/.{129}// was to remove the first 129 characters of the file. This was header info only, and confused the issue. Maybe I should have used ^, but since there is no g at the end of the line, doesn't it amount to the same thing? I mean the regex is going to be searched from the top each time, isn't it?
    Seems to work, but am I being sloppy?
    Simplicus.
      Anchoring a regex (with ^ or $) will nearly always make it more efficient, as it tells the engine that the expression can only match starting from (or ending with) one position.

      In this case, though, when you know you want to get rid of 129 characters, substr will definitely be faster. Something like: substr $text, 0, 129, ''; (oops, it *should* be length and not offset. Thanks btrott!)

        I was going to say that that looked wrong, but then I looked at the docs online (my work has 5.004_04) and found that that was valid. That's pretty nice. :)

        Although I think it should be 129 instead of 128, because it's not the index into the string, it's the length that you want to cut out... which is 129, right?

        So it should actually be

        substr $text, 0, 129, '';
        Other possibilities using substr:
        substr($text, 0, 129) = '';
        or
        $text = substr $text, 129;
        The first uses substr as an lvalue, setting the first 129 characters to ''. Or eliminating them, in other words.

        The second is more "standard"; it sets $text to characters 129-the end of $text.

        All have the same result.