Saturday, July 7, 2007

Just perl !!!

Believe it or not is a complete program (business logic included):
$_ = '1 4, 4 5, 6 /, 5 /, x, 0 1, 7 /, 6 /, x, 2 /, 6';
s/\/, (\d)/\/ $1, $1/g;
s/\/, (x)/\/ 10, x/g;
s/(\d )\//$1.(10-$1)/ge;
s/x, (\d \d)/x $1, $1/g;
s/x/10/g;
s/(((,?)( \d+)+){10}).*/$1/;
s/(\d+) (\d+)/$1+$2/ge;
s/(\d+) (\d+)/$1+$2/ge;
my $total;
s/(\d+)/$total+=$1/ge;
print;
see it in action

read more

No comments: