bukzor <> writes:
> Hi,
>
> I'm trying to find the fastest way in perl to see if a name contains
> another.
>
> I've a list of 2704 names (aka "A")
>
> I've another name (aka "B")
<snip>
> foreach $t (keys %A) {
> $v = $B;
> $v = s/$t//;
> if ($v ne $B) {
> print "MATCH"
> }
> }
Did you notice that doesn't work? $v = s/../../; assignes the number of
replacements of $_ into $v.
For an unordered list of strings of lengths >= 1, the fastest check
would probably be to use the index() function, though it may not be that
much more or even less fast than a regex match (NOT a replace!).
See perldoc -f index and perldoc perlretut.
--
Joost Diepenmaat | blog:
http://joost.zeekat.nl/ | work:
http://zeekat.nl/