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

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Given a string consisting of runs of chars, eg.

0 1 2 3 4 5 + 6 01234567890123456789012345678901234567890123456789012345 +67890 my $string =' aaaa bbbbccccccccbbbb aaaabbbbbcdddddddddddddddd +dddd';

I need to iterate over the string returning, (value, startpos and length) after each iteration. So the values for the above string would be

(' ',0,4), ('a',4,4),(' ',8,4),('b',12,4),('c',16,8),('b',24,4),(' ',28,3),('a',31,4),('b',40,1)...

There is no significance in the choice of example string, each run could be of any char 0..255. Nor the lengths, the number of 4's and multiples thereof seems to be something to do with the repeat speed of my keyboard and my reaction time.

I don't really mind if that means I get an array with the values interleaved, 3 arrays with the triples spanning the arrays.

I've tried various methods, but I feel that a clever regex solution using \G and /cg in a loop would be possible and probably more efficient that most I've tried, but it escapes me. NOTE: My goal here is absolutely efficiency not keystroke golf.

I'll benchmark any and all solutions offered, what I'm really after is the regex solution if its possible and also alternative methods.

Thanks, BrowserUK


Okay you lot, get your wings on the left, halos on the right. It's one size fits all, and "No!", you can't have a different color.
Pick up your cloud down the end and "Yes" if you get allocated a grey one they are a bit damp under foot, but someone has to get them.
Get used to the wings fast cos its an 8 hour day...unless the Govenor calls for a cyclone or hurricane, in which case 16 hour shifts are mandatory.
Just be grateful that you arrived just as the tornado season finished. Them buggers are real work.


In reply to Efficient run determination. by BrowserUk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others about the Monastery: (3)
    As of 2019-05-26 13:27 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!