John W . Krahn schreef:
> Eric Krause:
>> I have a string like:
>> 11111xxx11xxxx111111xx11x1xxxx
>>
>> I would like to replace the 1's with the total of 1's like this:
>> 5xxx2xxxx6xx2x1xxxx
>
>
> $ perl -le'
> $_ = q[11111xxx11xxxx111111xx11x1xxxx];
> print;
> s/(1+)/@{[($l=$1)=~y|1|1|]}/g;
> print;
> '
> 11111xxx11xxxx111111xx11x1xxxx
> 5xxx2xxxx6xx2x1xxxx
> :-)
Aiaiaiai.
$ perl -le'
$_ = q[11111xxx11xxxx111111xx11x1xxxx];
print;
1 while s/(\d)(\d)/@{[0==print, $1+$2]}/;
print;
'
11111xxx11xxxx111111xx11x1xxxx
11111xxx11xxxx111111xx11x1xxxx
2111xxx11xxxx111111xx11x1xxxx
311xxx11xxxx111111xx11x1xxxx
41xxx11xxxx111111xx11x1xxxx
5xxx11xxxx111111xx11x1xxxx
5xxx 2xxxx111111xx11x1xxxx
5xxx 2xxxx 21111xx11x1xxxx
5xxx 2xxxx 3111xx11x1xxxx
5xxx 2xxxx 411xx11x1xxxx
5xxx 2xxxx 51xx11x1xxxx
5xxx 2xxxx 6xx11x1xxxx
5xxx 2xxxx 6xx 2x1xxxx
--
Affijn, Ruud
"Gewoon is een tijger."
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/