Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Re: Parse float from string

by samurai (Monk)
on Nov 05, 2002 at 00:22 UTC ( [id://210348]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://210348]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2024-04-18 06:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found