|Syntactic Confectionery Delight|
Efficient run determination.by BrowserUk (Pope)
|on Nov 14, 2002 at 09:23 UTC||Need Help??|
BrowserUk has asked for the wisdom of the Perl Monks concerning the following question:
Given a string consisting of runs of chars, eg.
I need to iterate over the string returning, (value, startpos and length) after each iteration. So the values for the above string would be
(' ',0,4), ('a',4,4),(' ',8,4),('b',12,4),('c',16,8),('b',24,4),(' ',28,3),('a',31,4),('b',40,1)...
There is no significance in the choice of example string, each run could be of any char 0..255. Nor the lengths, the number of 4's and multiples thereof seems to be something to do with the repeat speed of my keyboard and my reaction time.
I don't really mind if that means I get an array with the values interleaved, 3 arrays with the triples spanning the arrays.
I've tried various methods, but I feel that a clever regex solution using \G and /cg in a loop would be possible and probably more efficient that most I've tried, but it escapes me. NOTE: My goal here is absolutely efficiency not keystroke golf.
I'll benchmark any and all solutions offered, what I'm really after is the regex solution if its possible and also alternative methods.
Okay you lot, get your wings on the left, halos on the right. It's one size fits all, and "No!", you can't have a different color.