hi monks. so i have a simple i think question, but i cant find any easy or fast solution, so it is not so simple to me. :p Say, there is this scenario, where you have a variable which contains a string full of ones and zeroes like:

$string = "010011100001110110100110111000001";

What do you think would be the quickest, not only for the cpu but for writing too, way to create another string, with the number of continual zeroes in it. Let's say for the above $string, to create a new one with this format:

$string = "010011100001110110100110111000001"; $newString = "1, 2, 4, 1, 1, 2, 1, 5";

where 1 is for the first zero in $string, 2 for the 2 zeroes in third and fourth place, 4 for the 4 zeroes in 8th, 9th, 10th, and 11th place. etc... I m really sorry if you cant really make out what i mean, but english is not my native language. Any help would be appreciated.


In reply to string manipulation by kimlid2810

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, details, 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, summary, 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.