in reply to Re^3: compare files by words
in thread compare files by words

How about
use List::Util "min"; ... my $words = min(@words1, @words2); $total += $words; $bad += grep $words1[$_] ne $words2[$_], 0 .. ($words - 1); ... print "good:", $total - $bad;
possibly switching max for min.

Replies are listed 'Best First'.
Re^5: compare files by words
by blazar (Canon) on May 31, 2007 at 10:30 UTC
    use List::Util "min";

    Yep, I like and use that. But for two values only a simple ternary is more appropriate IMHO. Of course keeping a $total is also fine, interesting and I had thought of it myself. But after all the $bad vs $good one is more symmetric and thus I prefer it. That's just me of course.

      I've seen people get that "simple ternary" backwards :) and min reads a lot easier. In a one-liner, I'd use the ternary.

      You could do bad & good and no total and still have the grep do the counting of one or the other. Still not quite symmetric, though.