my $sum = 0;
while (<>) {
- chomp;
+ s/\s//g;
+ $_ = "($_)";
1 while
s/\((\d+)\)/$1/ ||
- s/(\([^\(\)]*?)(\d+)\s*\+\s*(\d+)([^\(\)]*\))/$1.($2+$3).$4/e ||
- s/(\([^\(\)]*?)(\d+)\s*\*\s*(\d+)([^\(\)]*\))/$1.($2*$3).$4/e ||
- s/(\d+)\s*([\+])\s*(\d+)/"$1$2$3"/ee ||
- s/(\d+)\s*([\*])\s*(\d+)/"$1$2$3"/ee;
+ s/(\([^\(\)]*?)(\d+)\+(\d+)([^\(\)]*\))/$1.($2+$3).$4/e ||
+ s/(\([^\(\)]*?)(\d+)\*(\d+)([^\(\)]*\))/$1.($2*$3).$4/e;
$sum += $_;
}
print "sum=$sum\n";