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

Hi monks I am trying to monitor a temperature from a temp probe and sound an alarm when its out of range. To capture the output from the temp monitor program i am using a line like this.

 $temp = `/usr/local/bin/pcsensor -f`;

The output of that program looks like this 2013/12/09 23:00:01 Temperature 71.83F

I want to just capture the temp without the other numbers or any letters. I have looked at sample code snippets but most capture all digits. I don't want the date and time. Anyone willing to help a perl newbie out? Thanks

Replies are listed 'Best First'.
Re: perl extract a specific # from string
by Preceptor (Deacon) on Dec 11, 2013 at 07:01 UTC

    The things you're looking for is a regular expression - read 'perlre'.

    For the sake of an example:

    my ( $temp_value ) = ( $temp =~ m/Temperature ([\d\.]+)F/ );
Re: perl extract a specific # from string
by hdb (Monsignor) on Dec 11, 2013 at 07:03 UTC

    There are many ways to do this, it is not difficult, and it is all explained in perlretut. I would propose to just pick the non-whitespace characters at the end of the string:

    $temp =~ /(\S+)$/;