in reply to Re^2: Longest match finding.
in thread Longest match finding.
Well, how do you as a human know which pattern to use?
Encode the same criterion in your program.
Maybe you meant to direct to the "most specific" pattern. Then just sort the patterns according to their specificity:
my @sorted_patterns = sort { my $spec_a = ($a =~ tr[.][.]); my $spec_b = ($b =~ tr[.][.]); $spec_b <=> $spec_a || $a cmp $b } @patterns;
|
|---|