Use the /e modifier to include code in the replacement part of the substitution:
$input =~ s/( +)/length $1/ge;
| [reply] [d/l] [select] |
Ingenious. I thought it has something to do with pack-unpack ( which I fear ).
| [reply] |
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';
| [reply] [d/l] |
| [reply] |
Something like s/(\s+)/length($1)/ge ?
This is untested code, please show some effort applying, questioning and understanding it.
| [reply] [d/l] |