Skip to content

Instantly share code, notes, and snippets.

@libitte
Created October 7, 2014 05:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save libitte/653ad78602cad88223dd to your computer and use it in GitHub Desktop.
Save libitte/653ad78602cad88223dd to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
use Text::Diff;
use Digest::MD5;
use Getopt::Long::Descriptive;
use File::Basename;
use Carp ();
use Tie::File;
my $ME = basename($0, '.pl');
my ($opts, $usage) = describe_options(
"$ME.pl %o",
["file1|f1=s", "file1"],
["file2|f2=s", "file2"],
["help", "print this message"],
);
if ($opts->help) {
print $usage->text;
exit;
}
unless ($opts->{file1} && $opts->{file2}) {
print '$opts->{file1} and $opts->{file2} are required.', "\n";
print $usage->text;
exit;
}
MAIN: {
my $file1 = $opts->{file1};
my $file2 = $opts->{file2};
my @file1;
tie @file1, 'Tie::File', $file1;
@file1 = sort { $a cmp $b } @file1;
my @file2;
tie @file2, 'Tie::File', $file2;
@file2 = sort { $a cmp $b } @file2;
my $diff = diff \@file1, \@file2;
unless ($diff) {
print "Files match!!!\n";
exit;
}
print "*** DIFF ***\n";
print "$diff\n";
exit;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment