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);

In reply to Re: Script to Find Differences Between Files by jwkrahn
in thread Script to Find Differences Between Files by lunchb0x

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.