Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi, i am new to perl and would really appreciate your help i would like to extract 3 variables from the string in the following format:
"43436 66 78 5333 3444 ... 345ms : 34.56ms : 45ms"
result should be $var1 = 345; $var2=34.56; $var3 = 45
these numbers are always at the end of the string, and
first one and last one are integers, but middle one is not.
Thanks
Mike

Replies are listed 'Best First'.
Re: extracting variables from a string
by davidrw (Prior) on Aug 03, 2005 at 20:52 UTC
    many ways, depending on the assumptions you want to make -- here are a couple:
    my $s = "43436 66 78 5333 3444 ... 345ms : 34.56ms : 45ms"; my @vars = $s =~ /([0-9.]+)ms/g; if( $s =~ /(\d+)ms : ([0-9.]+)ms : (\d+)ms/ ){ my @vars = ($1, $2, $3 ); }
      Thank you so much, that worked