in reply to Re: Longest match finding.
in thread Longest match finding.

But these patterns are not known while coding time. It will be extracted from live gateways.

Replies are listed 'Best First'.
Re^3: Longest match finding.
by Corion (Patriarch) on Dec 17, 2008 at 09:59 UTC

    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;