http://qs321.pair.com?node_id=636143
Category:
Author/Contact Info
Description: I've got piles of log files which also contain sdiff output. The width of the sdiff output is allowed to vary so I needed a program which could examine these files and find the pivot points. This is useful later if I want to find the sdiff markup and do highlighting or stuff.
#!perl
use strict;
use warnings;
no warnings 'uninitialized';
use Algorithm::Loops 'MapCarU';

my @cols =
    MapCarU {
        join '',
        map {
            /\S/
                ? $_
                : "\0"
        }
        @_
    }
    map { [ split // ] }
    <>;

my ( $best_col, $best_sum );
for my $starting_col ( 10 .. $#cols - 10) {
    my $sum = 0;
    for my $col ( 0 .. 9 ) {
        my $bits =
            unpack 'b*',
            $cols[$col] & $cols[ $starting_col + $col ];
         $sum += $+[0] - $-[0] while $bits =~ /11*/g;
    }

    if ( not( defined $best_col ) or $best_sum < $sum ) {
        $best_col = $starting_col;
        $best_sum = $sum;
    }
}

print "$best_col\n";