Victory (on a mini Perl contest)

cog on 2004-02-19T17:20:14

Mini Perl contest. The smallest amount of characters wins. The purpose is to convert every word with more than two characters to the following format: (first_letter)(number_of_letters_in_between)(last_letter).

Input:

this is an input line

Output:

t2s is an i3t l2e

Someone had already come up with this:

#!/usr/bin/perl -p s!(\w)(\w+)(\w)!$1.(length$2).$3!eg

and I considered it (for personal reasons) to be a personal matter. It took me a while (some minutes, I mean), but I finally came up with:

#!/usr/bin/perl -p s!(?<=\w)\w+(?=\w)!length$&!eg

Any other suggestion? :-)


BNased on the same idea...

bart on 2004-02-19T21:22:26

... but slightly shorter, is this:
s!\B\w+\B!length$&!eg

Re:BNased on the same idea...

cog on 2004-02-20T10:59:54

Awesome :-) This comes to prove timtowtdi :-)