#!/usr/bin/perl -w use strict; print "Content-type: text/html\n\n"; print "\n"; $_ = '1 4, 4 5, 6 /, 5 /, x, 0 1, 7 /, 6 /, x, 2 /, 6'; &printRow(); s/\/, (\d)/\/ $1, $1/g; # bonus for open spares s/\/, (x)/\/ 10, x/g; # bonus for marked spares s/(\d )\//$1.(10-$1)/ge; # remove / notation s/x, (\d \d)/x $1, $1/g; # bonus for open strikes s/x/10/g; # remove x notation s/(((,?)( \d+)+){10}).*/$1/; # trim to 10 frames s/(\d+) (\d+)/$1+$2/ge; # sum two throws in frame s/(\d+) (\d+)/$1+$2/ge; # sum bonus if any my $total; s/(\d+)/$total+=$1/ge; # convert to running total &printRow(); print "
\n"; sub printRow() { local($_) = $_; print "", map("$_", split(/,/)),"\n"; }