in reply to Re: how to count the number of repeats in a string (really!)
in thread how to count the number of repeats in a string (really!)
Then I'll break those substrings in parts, if abc is repeated i suspect also bc is repeated, isn't it?
I personally believe that if it were only a suspect it wouldn't be enough. The nice part is that it's obviously certain it is! Anyway, I like your approach very much. For completeness I'm recasting your code in a sub with a similar behaviour to the ones in previous code:
sub oha { my $s=shift; my %saw; while($s =~ /(..+)(?=.*?\1)/g) { for my $x (0..length $1) { @saw{ map {substr $1, $x, $_} $x+2..length $1 } = (); } } $saw{$_} =()= $s =~ /\Q$_/g for keys %saw; \%saw; }
Update: I see that you chaged your nodes content and that the original code is not there anymore. I recommend you to only post updates instead, and if you feel that something is wrong and needs to be "deleted", then possibly use <strike> tags. To keep the visual size of your node limited for those that do not want to read all of its details, you can also adopt <readmore> tags.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: how to count the number of repeats in a string (really!)
by oha (Friar) on Nov 16, 2007 at 14:58 UTC |