in reply to extracting number from string

Alternatively, use a regular expression capture.

$ perl -le ' $str = q{Price 15.40}; ( $str ) = $str =~ m{(\d+\.\d+)}; print $str;' 15.40 $

I hope this is useful.

Cheers,

JohnGG

Replies are listed 'Best First'.
Re^2: extracting number from string
by apl (Monsignor) on Mar 05, 2009 at 12:40 UTC
    For the general case, I'd replace m{(\d+\.\d+)} with m{(\d+\.?\d+)}, just in case a period is not specified in the price.