Perl Help

Hi

9:26pm up 551 days, 5:52, 19 users, load average: 1.51, 1.70, 1.77

    From the above output i want to extract the last three floating numbers\(1.51, 1.70, 1.77\) in a perl script. can anybody help how would be regular expression...

Reply ASAP :slight_smile:

"Reply ASAP" is not a good pattern :slight_smile: I learned to distinguish ASAP - as soon as possible, which people in USA are usually using as : do it right away, as opposed to "at your earliest convenience" - which politely says : do it when you have time, but please keep it in mind as a high priority.
So back on topic :
the regexp you probably need is "/[+-]?\d+\.\d+/;"

if all there floating point numbers are always present and preceded by "load average:" :

$string = '9:26pm up 551 days, 5:52, 19 users, load average: 1.51, 1.70, 1.77';
@nums = $string =~ /load average: ([\d.]+), ([\d.]+), ([\d.]+)/;
print "$_\n" for @nums;

keep it simple

$s="9:26pm up 551 days, 5:52, 19 users, load average: 1.51, 1.70, 1.77";
$index=rindex $s,":";
print substr($s,$index+1);

Thanks A lot its working fine