Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Efficient run determination.

by robartes (Priest)
on Nov 14, 2002 at 10:07 UTC ( #212799=note: print w/replies, xml ) Need Help??


in reply to Efficient run determination.

OK, I'm not really answering your question (I'm not using a regexp), and this is a method you have probably tried before, but if it's speed you want, how about simply converting the string to an array and looping once over its elements?
use strict; my $string=" aaaa bbbbccccccccbbbb aaaabbbbbcddddddddddddddddd +dddd"; my @listedstring= split//,$string; my $prev=shift @listedstring; my $currstart=my $index=0; for (@listedstring) { if ($_ eq $prev) { $index++; } else { print "('$prev',$currstart,".($index-$currstart+1).")\n"; $currstart=++$index; $prev=$_; } } print "('$prev',$currstart,".($index-$currstart+1).")\n";
Interesting problem, BrowserUk!

CU
Robartes-

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (16)
As of 2019-05-23 13:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you enjoy 3D movies?



    Results (144 votes). Check out past polls.

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