
viddy
Novice
Jul 14, 2009, 5:47 AM
Post #1 of 3
(994 views)
|
Hello, I am having a problem doing a simple array comparison. I know that I probably should have used a hash to do this but I would rather stick with the array approach just because I am not sure of what is wrong with it....Any how, basically I got 2 txt files that I want to compare and have a list printed out of the ones that are not in one of the lists when the script is done. The master list is the list of all possible numbers/codes and the compiled list is the ones that I have already done and want to rule out. I would like the final result to be a list of the numbers that were in the master list but not the compiled. I have posted my code. Thank you in advance. Any advice or feedback would be greatly appreciated! #!/usr/bin/perl use strict; use warnings; #open master list my @masterCodes; open(MASTER,"<master.txt") or die "Couldn't open file 1: $!\n"; while(<MASTER>) { chomp(); push(@masterCodes,"$_"); } #open compiled list my @compiledCodes; open(COMPILED,"<compiled.txt") or die "Couldn't open file 2: $!\n"; while(<COMPILED>) { chomp(); push(@compiledCodes,"$_"); } my $totalSize = $#masterCodes; my $i = 0; foreach my $code (@compiledCodes) { while ($i < $totalSize) { if ($code = $masterCodes[$i]) { print "$code\n"; } $i++; } }
|