factored out tens place, combined lots of regexes. Four characters for exponentiation. I find being at the back of the pack terribly motivating...
#!perl -lap
for(@F){/(ho)|(mi)|(bi)/&&do{$$_ and$n*=1e3**$_ for 1..3;$a+=$n;$n=0;next};s/hu/$n*=100;next/e;$o=0;/te[ne]/and$o=10;/(on)|(wo)|(th)|(fo)|(fi)|(si)|(se)|(ei)|(ni)|()(le)|(lv)/&&do{$$_ and$o+=$_ for 1..12};/ty/&&do{$o=2if/tw/;$o*=10};$n+=$o}$_=$n+$a;1while s/^(-?\d+)(\d{3})/$1,$2/
|
First pass, simplest possible algorithm, with the commafication stolen from the faq
Is this the first "goto" in perl golf?
#!perl -lap
for(@F){/hun/&&do{$n*=100;next;};/tho/&&do{$a+=$n*1e3;$n=0;next};/mil/&&do{$a+=$n*1e6;$n=0;next};/bil/&&do{$a+=$n*1e9;$n=0;next};$o=0;/ten/and$o=10;/ele/and$o=11;/twe/and$o=12;/ty/&&do{/tw/and$o=2;/th/and$o=3;/fo/and$o=4;/fi/and$o=5;/si/and$o=6;/se/and$o=7;/ei/and$o=8;/ni/and$o=9;$o*=10;goto A};/on/and$o++;/wo/and$o+=2;/th/and$o+=3;/fo/and$o+=4;/fi/and$o+=5;/si/and$o+=6;/se/and$o+=7;/ei/and$o+=8;/ni/and$o+=9;/tee/and$o+=10;A:$n+=$o}$_=$n+$a;1while s/^(-?\d+)(\d{3})/$1,$2/
|