Perl: Comparing to two files and displaying the differences

Hi,

I'm new to perl and i have to write a perl script that will compare to log/txt files and display the differences. Unfortunately I'm not allowed to use any complied binaries or applications like diff or comm.

So far i've across a code like this:

use strict;
use warnings;

my $list1;
my $list2;

my @list1 = qw(111 222 333);
my @list2 = qw(222 333 444);

LIST2: foreach $list2 (@list2){
LIST1: foreach $list1 (@list1){
if ("$list2" eq "$list1") {
next LIST2;
}
}
print "$list2 \n";
}

When I run this I get 444 returned as expected. However I'm wondering how I can change this so that it compares two log or txt files (ie. list1.txt and list2.txt).

Any help at all would be great.

Thanks in advanced.

Why not? Why reinvent the wheel in Perl?
diff and comm are shipped with almost every *nix system, they are fast, flexible, rich-featured, less buggy and they have been tested again and again over the years.

tyler_durden

I've just started learning perl as part of an IT course and this is our first task is to compare two files without using diff or comm.