I hope I did understand your problem. Here is my sample code. Kindly check it if the flow and output fits to the solution of your problem. If it didn't, I hope it can give you some clues. Just like Javafan said check each word of "my_name" if they all exist in one of the string of database "db_name".
#!/usr/bin/perl -w
@my_name=("Acidovorax","JS42"); #name to be searched...
#...split by term/words
@db_name=("Acidovorax sp. JS42", #data base of names in array
"JS42 Acidovorax sp.",
"JS42 sp. Acidovorax",
"JS53 sp. Acidovorax",
"JS42 sp. Axidovorax",
"JS42Acidovorax sp. "
);
my $ctr;
#----compare strings in $db_name 1 at a time
foreach my $db_each (@db_name){
#----search each term/word of @my_name in $db_each
foreach($ctr=0; $ctr<=$#my_name; $ctr++)
{
#----if a term/word not found break the loop
last if($db_each !~ /\b$my_name[$ctr]\b/i);
}
#----this will be true if inner foreach didn't break
if($ctr==$#my_name+1)
{
print "$db_each\n"; #print the matched name
}
}
<>;
I have mention the "term/word" in the comment. It might be that two words in your "my_name" is considered as one term or two or more words separated by space.
The code above does not support if a word should exist 2 or more times in any order. example: my_name = "high class bacteria f7-52 high fever". Just mentioning this condition for more flexibility to your program. It's still up to you.
|