Hi,
I would like to know if there's an easy way to push elements to an array only if they are unique. With my current code, I end up with some duplicates.
Reference.txt
Main.txt
I would like to know if there's an easy way to push elements to an array only if they are unique. With my current code, I end up with some duplicates.
Reference.txt
Code:
TE|Value TE
TY|Value TY
RW|Value RW
Main.txt
Code:
ID0199|Record 0199|TE
ID2182|Record 2182|RW
ID4688|Record 4688|RW
ID4785|Record 4785|TY
ID7332|Record 7332|TE
Code:
# Open Main.txt
open(MAIN,"Main.txt") || die("Can't open file");
# Open Reference.txt
open(REFERENCE,"Reference.txt") || die("Could not open file!");
@References = <REFERENCE>;
close(REFERENCE);
# Loop Around Main.txt
while ( my $Mains = <MAIN> ) {
chomp $Mains;
my @Main = split(/\|/,$Mains);
# Loop Around Reference.txt
foreach my $Ref (@References) {
chomp $Ref;
my @Reference = split(/\|/,$Ref);
# Create New Array
if ($Reference[0] eq $Main[2]) {
push(@ReferencesExists,[@Reference]);
}
}
}
return @ReferencesExists;
close(MAIN);