Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Find the pivot point for sdiff output

by diotalevi (Canon)
on Aug 30, 2007 at 17:16 UTC ( #636143=sourcecode: print w/replies, xml ) Need Help??
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";

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://636143]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2020-10-28 02:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (259 votes). Check out past polls.

    Notices?