"Ryan Moszynski" schreef:
> i have this string extracted from a text file i'm writing a program
> to process:
>
>  test_freq     = 1.0001;
>
> and i have to extract the "1.0001"
>
> i can't count on the whitspace being where it now is.
>
> I would like to change this line of perl
>
>  $getTestFRQ =~ s/\D+//g;
>
> so that instead of killing all non digit characters, it will kill all
> non digit characters except for the period.
>
> How do i do this?


Possible:

  s/[^\d.]+//g

but not safe.

Variant:

  ($getTestFRQ) = /=\s*(\d+\.\d+)/ ;

assuming the string is in $_.


You could also use 'test_freq' as a hash key:

  my %h ;
  /^\s*(\w+)\s*=\s*(\d+(?:\.\d*)?)/ and $h{lc $1} = $2 ;

(untested)

-- 
Affijn, Ruud

"Gewoon is een tijger."



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to