in reply to Matching Many Strings against a Large List of Hash Keys (case insensitively, longest key first)
use Regexp::Assemble; use List::Util qw(reduce); # XXX why have a hash if its values are not used? my @keys = map { quotemeta } keys %hash; my $key_re = Regexp::Assemble->new->add(@keys)->re; for my $string (@strings) { my $match = reduce { length($a) > length($b) ? $a : $b } ($string =~ /\b($key_re)\b/gi); print "Found '$match' in '$string'\n" if defined $match; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Matching Many Strings against a Large List of Hash Keys (case insensitively, longest key first)
by JavaFan (Canon) on May 14, 2010 at 17:35 UTC | |
by repellent (Priest) on May 14, 2010 at 17:58 UTC | |
by JavaFan (Canon) on May 14, 2010 at 18:01 UTC | |
by repellent (Priest) on May 14, 2010 at 19:04 UTC | |
|
Re^2: Matching Many Strings against a Large List of Hash Keys (case insensitively, longest key first)
by Anonymous Monk on May 14, 2010 at 18:03 UTC |