Hmm. I'm not sure that I entirely understand the problem. My guess is
that you have a list of words (that I will call the "catalog"), and a
list of words (that I will call the "query"). For each element of the
query you want to generate a list of the words in the catalog that
contain contain the query element as a substring. Is that an accurate
restatement of the problem you are trying to solve?
If so, this should be a reasonably efficient solution:
use strict;
my @catalog = qw( and the she end why not );
my @query = qw( no an he it );
my $solution;
foreach my $substr ( @query ) {
foreach my $word ( @catalog ) {
if ( index( $word, $substr ) > -1) {
push( @{ $solution->{ $substr } }, $word );
}
}
}
use Data::Dumper;
print Dumper( $solution );
$VAR1 = {
'he' => [
'the',
'she'
],
'no' => [
'not'
],
'an' => [
'and'
]
};
HTH.
-Chris
Chris Staskewicz wrote:
>Is there an efficient method to find all "continuous" substrings of a
>string. For example, in the word "green", I'd like to parse out:
>
>g, r, e, e, n, gr, re, ee, en, gre, ree, and so on...
>
>A for loop with a substr command works, but the program is taking forever
>to run. I'm doing this for about 20,000 strings with max(string) = 50 and
>min(string) = 1 for all strings in the set. I'm comparing these parsed
>substrings to another string and flagging any matches.
>
>Thanks,
>
>Chris.
>
> --------------------------------------------------------------------
> Chris Staskewicz
> http://www.ZyGob.com/cjs
> http://www.math.utah.edu/~cjs
> --------------------------------------------------------------------
>
>_______________________________________________
>Boston-pm mailing list
>[EMAIL PROTECTED]
>http://mail.pm.org/mailman/listinfo/boston-pm
>
>
>
>
_______________________________________________
Boston-pm mailing list
[EMAIL PROTECTED]
http://mail.pm.org/mailman/listinfo/boston-pm