Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Find the pivot point for sdiff output

by diotalevi (Canon)
on Aug 30, 2007 at 17:16 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: sourcecode [id://636143]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (2)
As of 2024-04-20 03:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found