in reply to Script to Find Differences Between Files

1 #!/usr/bin/perl -w You should use the strict pragma as well: use strict; 3 #open file 4 open(OUTFILE, ">/media/hda3/differences.txt") or die("Unable t +o open file"); 5 6 #read file into array 7 @data = <FILE>; The filehandle FILE has not been opened yet so @data will be filled wi +th nothing; 9 #close file All of the comments up to now have been superfluous. 10 close (FILE); 11 12 #Used to test if data is read into array 13 #print $data[2]; How is that supposed to "test if data is read into array"? 15 #open file to save differences 16 open(FILE, "/media/hda3/differences.txt"); You are opening the file too late to be able read it on line 7. You s +hould *always* verify that the file opened correctly: open FILE, '<', '/media/hda3/differences.txt' or die "Cannot o +pen '/media/hda3/differences.txt' $!"; 18 #loop to determine differences 19 for ($i=0; $i<377; $i++) 20 { 21 for($j=$i+1; $j<377; $j++) 22 { Why 377? Why not just use the actual size of the array: for my $i ( 0 .. $#data ) { for my $j ( $i + 1 .. $#data ) { 23 $command_line = "cmp -l /media/hda3/2967test/" $data[$i] +" /media/hda3/2967test/" $data[$j] "| wc -l"; There should be operators between the strings and the variables: $command_line = "cmp -l /media/hda3/2967test/" . $data[ $ +i ] . " /media/hda3/2967test/" . $data[ $j ] . " | wc -l"; Or just use string interpolation: $command_line = "cmp -l /media/hda3/2967test/$data[$i] /m +edia/hda3/2967test/$data[$j] | wc -l"; 24 $diff_count = system $command_line; system does not return what you seem to think it returns. You probabl +y want something like: my $command_line = "cmp -l /media/hda3/2967test/$data[$i] + /media/hda3/2967test/$data[$j]"; my $diff_count = () = `$command_line`; 25 print OUTFILE ($data[$i], "\t", $date[$j], "\t", $diff_co +unt, "\n"); The strict pragma would have caught your typo, there is no @date array + defined. 26 } 27 } 28 29 #close file 30 close(FILE);