Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem matching a patter

Status
Not open for further replies.

john99999

Instructor
Apr 29, 2005
73
0
0
US
root@server1 [/]# cat ss4
#!/usr/bin/perl
$a=`uptime`;
$a =~ /[\d*],/;
#echo "a = $a"
if ( $a < 5.2 ){
print $a;
}


root@server1 [/]# ./ss4
1:04pm up 29 days, 18:41, 1 user, load average: 0.24, 0.33, 0.29

How do I get this to display only the 0.24 and not the full output of uptime?
 
Code:
#!/usr/bin/perl

$_ = '1:04pm  up 29 days, 18:41,  1 user,  load average: 0.24, 0.33, 0.29';

s/.* ([\d.]+), [\d.]+, [\d.]+$/$1/;

print $_;


Kind Regards
Duncan
 
Code:
qx[uptime] =~ /(\d{1,2}\.\d{1,2})/;
print "Load average = $1\n";
 
Think of it as 'quote and execute'. It has the same effect as backticks but I find it makes the intent clearer. So for example
Code:
my @files = qx[ls];
puts each line of the output from the ls command into the array @files.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top