Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Efficient run determination.

by tommyw (Hermit)
on Nov 14, 2002 at 10:11 UTC ( #212802=note: print w/replies, xml ) Need Help??


in reply to Efficient run determination.

Is $string=~/((.)\2*)/g what you're looking for?

#! /usr/bin/perl -w use Data::Dumper; use strict; my $string =' aaaa bbbbccccccccbbbb aaaabbbbbcdddddddddddddddd +dddd'; my $pos=0; my @triples=(); my @reps=$string=~/((.)\2*)/g; while (@reps) { my $hits=shift @reps; my $char=shift @reps; push @triples, [$char, $pos, length $hits]; $pos+=length $hits; } $Data::Dumper::Indent=0; print Dumper @triples; __DATA__ $VAR1 = [' ',0,4];$VAR2 = ['a','4',4];$VAR3 = [' ','8',4];$VAR4 = ['b' +,'12',4];$VAR5 = ['c','16',8];$VAR6 = ['b','24',4];$VAR7 = [' ','28', +3];$VAR8 = ['a','31',4];$VAR9 = ['b','35',5];$VAR10 = ['c','40',1];$V +AR11 = ['d','41',20];

Memo to self: must learn to use Data::Dumper properly ;-)

--
Tommy
Too stupid to live.
Too stubborn to die.

Log In?
Username:
Password:

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

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



    Results (153 votes). Check out past polls.

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