#!/bin/perl -w use diagnostics; use strict; use warnings; ############################################################ sub getAllLinesFromAFileandReturnItAsAnArray($) { my ($FILE) = $_[0]; #Redundant check. This code should be unreachable just by #the way I defined this sub '($)'. I do manual checking #of each varible as an anal principle. Just my style - Kristofer if (!defined($FILE)) { die ("I did not receive a filename"); } open my $FileDescripter => $FILE or die "Could not open '$FILE'\n"; my @ListOfStringsToReturn = <$FileDescripter>; close $FileDescripter; chomp @ListOfStringsToReturn; # my @ListOfStringsToReturn = (); # open (FileDescripter, "$FILE"); # while () # { # if (defined($_)) # { # chop; # push @ListOfStringsToReturn, $_; # } # } # close(FileDescripter); return @ListOfStringsToReturn; } #=========================================================== my $FirstFile = "FileOne.txt"; my $SecondFile = "FileThree.txt"; my @FileOne = getAllLinesFromAFileandReturnItAsAnArray($FirstFile); my @FileTwo = getAllLinesFromAFileandReturnItAsAnArray($SecondFile); for (my $i = 0; $i < @FileOne; $i++) { print "Comparing Line $i in $FirstFile ... "; my $test = undef; for (my $j = 0; $j < @FileTwo; $j++) { if ($FileOne[$i] eq $FileTwo[$j]) { print " matched to line $j in $SecondFile\n"; print " FileOne: '$FileOne[$i]'\n"; print " FileTwo: '$FileTwo[$j]'\n"; #Setting j to @FileTwo will kill this loop $j = @FileTwo; $test = 0; } } if (!defined($test)) { print " not matched. Compared to $#FileTwo entries\n"; } }