Syntactic Confectionery Delight | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Inspired by today's how to count the no of repeats in a string, I came up with an admittedly artificial but possibly very interesting problem: that of counting for a string the repetition count of each substring that is actually repeated. For example, given the string
I see that -limiting ourselves to substrings of length 2 or more- we have the following counts:
One possible way to get those counts is as follows -I'm casting the thing in the form of a sub-:
In fact, print Dumper count1 $str; gives me:
To my unpleasant surprise, if I change .{2,} to .+ I do not get all substrings (of length 1):
And I can't understand why... I personally believe that map based solutions are often very cute and so I rolled my own too:
But the latter
And I can't understand why, either. What's your take on the problem? In reply to how to count the number of repeats in a string (really!) by blazar
|
|