- or download this
use Parse::RecDescent;
...
print $g->weight("Pb(CO3)2"), $/;
# prints 327
- or download this
weight : compound { $item[1] }
compound : group(s) { sum( @{$item[1]} ) }
...
| { 1 }
element : /[A-Z][a-z]*/ { $weights{ $item[1] } }
| "(" compound ")" { $item[2] }