Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

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";

-xdg

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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2019-06-18 11:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Is there a future for codeless software?



    Results (81 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!