in reply to Re: Parse float from string
in thread Parse float from string

Unfortunately, that won't catch the period character. I would use transliteration, IF you know what characters you should ignore.

$string =~ y/A-Za-z //d;

That'll remove alphabeticals and spaces. However, you may have to specify more characters if there's more garbage in your $string's.

--
perl: code of the samurai

Replies are listed 'Best First'.
Re: Re: Re: Parse float from string
by mpeppler (Vicar) on Nov 05, 2002 at 00:40 UTC
    Sorry if I misread - the original poster had a parseInt() sub defined...
    To parse a float:
    sub parseFloat { my $str = shift; $str =~ /([\d\.]+)/; return $1; }
    Michael
      That is not going to work for: -11.10 11.10.11