in reply to comparing files
# First suggestion: add error checking. open (ONE, $file1) or die "Couldn't open $file1: $!\n"; open (TWO, $file2) or die "Couldn't open $file2: $!\n"; # 2nd suggestion: check syntax. while ($line1 = <ONE>) { # 3rd suggestion: eliminate unneeded loops. $line2 = <TWO>; # 4th suggestion: don't chomp if you don't need to. # 5th suggestion: If you don't need the whole array, don't keep it +. $element1 = (split ' ', $line1, 2)[0]; $element2 = (split ' ', $line2, 2)[0]; # 6th suggestion: Handle either or both cases. if ($element1 ne $element2) { print "$element1 does not equal $element2 at line $.\n"; } else { print "$element1 is the same in both files at line $.\n"; } }
-sauoq "My two cents aren't worth a dime.";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: comparing files
by Anonymous Monk on Aug 23, 2002 at 15:28 UTC | |
by mephit (Scribe) on Aug 23, 2002 at 21:09 UTC |