in reply to Re^3: Reg exps?
in thread Reg exps?
the program fails to find a single match. I doubt this is want the OP wants. The problem is that you're using different "word" definitions for "my_name" and "db_name". Either split both on whitespace, or both on \b, or it becomes trivial to find examples where the search is going to return the wrong answer. For instance:@my_name=("Acidovorax", "sp.", "JS42");
use 5.10.0; use strict; no warnings; my @names = ("Acidovorax JS42", "Acidovorax sp. JS42"); my @db_names = ("Acidovorax sp. JS42", #data base of names in array "JS42 Acidovorax sp.", "JS42 sp. Acidovorax", "Acidovorax JS42", "JS53 sp. Acidovorax", "JS42 sp. Axidovorax", "JS42Acidovorax sp. " ); foreach (@names) { say; my %name; @name{+split} = (); foreach (@db_names) { my %copy = %name; delete $copy{$_} for split; say "\t$_ is ", (keys %copy ? "not a " : "a "), "match"; } } __END__ Acidovorax JS42 Acidovorax sp. JS42 is a match JS42 Acidovorax sp. is a match JS42 sp. Acidovorax is a match Acidovorax JS42 is a match JS53 sp. Acidovorax is not a match JS42 sp. Axidovorax is not a match JS42Acidovorax sp. is not a match Acidovorax sp. JS42 Acidovorax sp. JS42 is a match JS42 Acidovorax sp. is a match JS42 sp. Acidovorax is a match Acidovorax JS42 is not a match JS53 sp. Acidovorax is not a match JS42 sp. Axidovorax is not a match JS42Acidovorax sp. is not a match
|
|---|