use strict; use warnings; # take the files as command line arguments # @ARGV contains all arguments passed in my $first_file = shift (@ARGV); my $second_file = shift (@ARGV); # double check that the file exists # that they can be read # and that they are text unless ((-e $first_file) and (-r $first_file) and (-T $first_file) and (-e $second_file) and (-r $second_file) and (-T $second_file)) { die ("Can't open one of the files!"); } open("FIRST", "< $first_file") or die ("Can't open $first_file because $!"); open("SECOND", "< $second_file") or die ("Can't open $second_file because $!"); my $linenumber = 0; while (1) { # we can use an infinite loop because # we have a last in here... # I could have compressed everything into the # conditional () but that makes it harder # to understand what is going on my $line1 = ; my $line2 = ; last unless ($line1 and $line2); $linenumber++; if ($line1 eq $line2) { print "$linenumber matches on each file!"; # note we used eq # == is for numerical values # eq is for strings } } print "We processed $linenumber lines\n";