in reply to Re: How can I replace space sequences in a string with the number of spaces in each sequence?
in thread How can I replace space sequences in a string with the number of spaces in each sequence?

By the way: what's your solution, if you have to do the same, but with 8 character blocks. So decompose the string into 8 character blocks ( it is promised that its length is an integer multiple of 8 ), and make the substitution within each block, the blocks separated by '/'.
my $input = 'r k rpp pp'; my $output = 'r3k2r/pp4pp';
  • Comment on Re^2: How can I replace space sequences in a string with the number of spaces in each sequence?
  • Download Code

Replies are listed 'Best First'.
Re^3: How can I replace space sequences in a string with the number of spaces in each sequence?
by LanX (Saint) on Feb 04, 2015 at 12:03 UTC

    I would nest regexes by calling a function on each 8block.

    How would you implement it ?

    update

    Or

  • split 8 blocks to array
  • replace whitespace for each element
  • join array with separator

    Can be done in a one liner with map .

    Cheers Rolf

    PS: Je suis Charlie!

      This is tested:
      my $fen=join('/', map { $_=~s/( +)/length $1/ge; $_; } $self->{rep}=~/.{8}/g );
        you might be interested in the new /r flag to avoid adding $_ explicitly at the end of map.

        my $fen= join '/', map { s/( +)/length $1/ger } $input =~ /.{8}/g;

        Cheers Rolf

        PS: Je suis Charlie!