kimlid2810 has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: string manipulation
by hdb (Monsignor) on May 18, 2013 at 19:15 UTC | |
|
Re: string manipulation
by aitap (Curate) on May 18, 2013 at 19:16 UTC | |
|
Re: string manipulation
by choroba (Cardinal) on May 18, 2013 at 19:18 UTC | |
|
Re: string manipulation
by roboticus (Chancellor) on May 18, 2013 at 21:17 UTC | |
|
Re: string manipulation
by Not_a_Number (Prior) on May 18, 2013 at 19:19 UTC | |
|
Re: string manipulation
by johngg (Canon) on May 18, 2013 at 23:57 UTC | |
|
Re: string manipulation
by kimlid2810 (Acolyte) on May 18, 2013 at 19:24 UTC | |
by LanX (Saint) on May 18, 2013 at 19:39 UTC |