Make your own free website on
File    Comparision

# The following program compares teh two files specified at the command
# prompt, syntax for comparing files is Perl file1 file1
# File1 is taken as master file, with which the other file is compared
# I was unable to enclose FH1 FH2 in while loop in greater than sign and less 
# than sign due to HTML editor interpretation, so it is just written as FH1 and FH2
# you have to enclose it appropriately for using this code.

#Exit if the number of arguments are not complete
if ($ARGV[0] eq ""|| $ARGV[1] eq "" ) 
  print "Usage : comp file1 file2\n";
  print "$ARGC";

# Open the file specified on command Line
open (FH1,$ARGV[0]);
open (FH2,$ARGV[1]);

$diff = 0;

# Filename specified first is the master file to which the file specified
# second is compared.
while (FH1)
  $filecontents = ;
  if ($_ ne $filecontents)
    print "$diff $_";
    print "$diff $filecontents";
while (FH2)
  print "$diff\n";
  print "$diff $filecontents\n";
close (FH1);
close (FH2);

Back To Main Page: