in reply to Re2: split question
in thread split question

That'll teach me to try and one-line my original solution.:(

For what it's worth, I didn't say that the last one would be more efficient, but I did say it would work ;(.

The original was

#! perl -sw use strict; my $var = "xxx:12345 yyy:54321 zzz:13245"; my $p=0; do { ($p=index($var, ':', $p+1 )) > -1 and print substr( $var, $p-3,3),$/; } while ($p > -1);

but I didn't like the double test against -1, so I tried to get rid of it. Don't know how I missed that it printed the extra one. A case of seeing what I wanted to see I guess.

I'm not that surprised that doing the looping inside the regex engine is more efficient than at user level. I'm guessing that it makes a single pass looking for fixed anchors like the : when the /g options is used. I am surprised how much more efficient it is.

Nice benchmark BTW. Something I need to get better at.


Cor! Like yer ring! ... HALO dammit! ... 'Ave it yer way! Hal-lo, Mister la-de-da. ... Like yer ring!