in reply to Re: How to avoid an alphabet and integer next to it in a string?
in thread How to avoid an alphabet and integer next to it in a string?

Yes, this is what I was looking for. Thanks! I tried avoiding H in C6H9. It turned out to calculate C69 giving me a wrong result. Of course, I was foolish enough to try this.
  • Comment on Re^2: How to avoid an alphabet and integer next to it in a string?

Replies are listed 'Best First'.
Re^3: How to avoid an alphabet and integer next to it in a string?
by piscean (Acolyte) on Mar 21, 2014 at 18:02 UTC
    my $molform = <STDIN>; $molform =~ s/[^a-zA-G0-9]//g; my $molmass = new Chemistry::MolecularMass; my $mass = $molmass->calc_mass("$molform");
      $molform =~ s/[^a-zA-G0-9]//g;

      Just eliminate the Hydrogen:

      $molform =~ s/H\d*//g;
        It says Forbidden chars. No output at all!