Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: Elegant way to split into sequences of identical chars?

by xdg (Monsignor)
on Nov 30, 2005 at 03:49 UTC ( #512842=note: print w/replies, xml ) Need Help??

in reply to Elegant way to split into sequences of identical chars?

Alas! it would be perfect, if no postprocessing was necessary on the match expression result!

Hardly elegant, but along the lines of the many other worthy entries. (Awful hack with $a to avoid declaring it.) Does not have to throw anything away. And probably benchmarks worse given the perl evaluation each time through!

my $line = "xx556xx"; my @list = $line =~ m/((??{ $a = substr( $line, pos($line), 1); $a ? q +uotemeta($a) . '+' : '$' }))/g; print "@list";


Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://512842]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (8)
As of 2020-01-25 23:12 GMT
Find Nodes?
    Voting Booth?