in reply to Finding all substrings
or you could have better space efficiency by keeping a list of offsets in an array, each index indicating the substring length... like so...
Untested, but now @result should hold lists of offsets, with the primary index being the length of the substr... which uses much less space...foreach my $length (1..length($string)) { foreach my $offset (0..length($string)-$length) { # push @result,substr($string,$offset,$length); push @{$result[$length]}, $offset; } }
really there are endless possibilities... so how can you narrow it down?
- Ant
- Some of my
best work - (1 2 3)
|
|---|