#!/usr/bin/perl # a lame line-by-line file comparision done for Rav ;-> # #==========================================# # Author: Marius Feraru aka AltBlue # # E-Mail: altblue@tuiasi.ro # # URL : http://www.cs.tuiasi.ro/altblue/ # # http://bofh.mednet.ro/altblue/ # #==========================================# $file1 = $ARGV[0]; $file2 = $ARGV[1]; open(F,$file1) || die "cannot open '$file1': $!\n"; @file1 = ; close(F); open(F,$file2) || die "cannot open '$file2': $!\n"; @file2 = ; close(F); $ok1 = 1; $ok2 = 1; foreach(@file1) { unless(ab_isin($_,\@file2)) { print "bleah. '$_' is not a line in '$file2'.\n"; $ok1 = 0; } } foreach(@file2) { unless(ab_isin($_,\@file1)) { print "bleah. '$_' is not a line in '$file1'.\n"; $ok2 = 0; } } if($ok1 && $ok2) { print "'$file1' and '$file2' contain exactly the same lines.\n"; } elsif($ok1) { print "'$file1' is included in '$file2'.\n"; } elsif($ok2) { print "'$file2' is included in '$file1'.\n"; } else { print "'$file1' and '$file2' are different.\n"; } #========================================================================= # usage ab_isin($var,\@array) # - returns 1 if $var is a member of @array, undef unless. #========= sub ab_isin { local ($v,@m)=($_[0],@{$_[1]}); foreach(@m){ return 1 if("$v" eq "$_"); } }