in reply to Re^4: Permutation with repetitions
in thread Permutation with repetitions
Oh, now your question is clearer. The easiest thing is to use a hash to track the frequencies, eg.
my $str = "aaaabdbbdaccdacdaaabdcd"; my $n = 3; my %freq; for my $p (0 .. length($str) - $n) { $freq{substr($str, $p, $n)}++; } for my $ng (sort keys %freq) { printf "%3d %s\n", $freq{$ng}, $ng; }
|
|---|