in reply to Re: Finding all substrings
in thread Finding all substrings
The only trick I have left is Inline::C... I'll leave that as an exercise for the reader.{ my @cache; sub substrings { $_ = shift; return &{$cache[length($_)]} if exists $cache[length($_)]; my $sub = 'sub { return ('; foreach my $len (1..length($_)-1) { foreach my $off (0..length($_)-$len) { $sub .= "substr(\$_,$off,$len),"; } } $sub .= "\$_)};"; $cache[length($_)] = eval $sub; return &{$cache[length($_)]}; } }
-sam
|
|---|