in reply to Finding all substrings

I guess the real question is... what are you using this for... you could be more efficient by waiting till you need a set of substrings, then generating and caching all the 3 letter substrs when you need a 3 letter substr... but that only works for certain situations...

or you could have better space efficiency by keeping a list of offsets in an array, each index indicating the substring length... like so...

foreach my $length (1..length($string)) { foreach my $offset (0..length($string)-$length) { # push @result,substr($string,$offset,$length); push @{$result[$length]}, $offset; } }
Untested, but now @result should hold lists of offsets, with the primary index being the length of the substr... which uses much less space...

really there are endless possibilities... so how can you narrow it down?

                - Ant
                - Some of my best work - (1 2 3)