#!/usr/bin/perl # # geekdiff - show significant differences in geek codes # Copyright (C) 2004 Clifford Wolf # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # (Yes, this script isn't written with maintainability in mind.. ;-) my @prefix = qw(G[A-Z] d s a C U L E W N o K w O M V PS PE Y PGP P t 5 X R tv b DI D G e h r [xyz]); my (@av, @results, %codes) = (@ARGV); if ($#av < 1) { print STDERR "Usage: ./geekdiff.pl file1 file2 [ file3 .. ]\n"; exit 1; } while (<>) { next if /^(-|Version:)/; code: foreach my $code (split /\s+/) { foreach my $pf (@prefix) { next unless $code =~ /^!?$pf/; $codes{$pf}{$ARGV} = $code; next code; } print "WARNING: Unmatched code $code in $ARGV:$.\n"; } } pf: foreach my $pf (@prefix) { my ($delta, %chars, $c) = (0); defined $codes{$pf}{$_} ? 1 : next pf foreach (@av); foreach (@av) { $chars{$_}=1 foreach (split(//, $codes{$pf}{$_})); } foreach $c (keys %chars) { my ($min, $max) = (9999, 0); foreach (@av) { my $t = $codes{$pf}{$_}; $t =~ s/[^$c]//g; $min = length $t < $min ? length $t : $min; $max = length $t > $max ? length $t : $max; } $delta = sprintf "%3d", $delta + abs($max - $min); } next if $delta < ($#av+1)*2; $delta .= sprintf " %-19s", $codes{$pf}{$_} foreach (@av); push @results, $delta; } print $_, "\n" foreach (reverse sort @results); exit 0;