Apr 12, 2009, 8:39 AM
Post #1 of 3
Unwanted line feeds
This is my first post, and I am just cracking the book "O'Reilly CGI Programming" .
There is an example perl script I'm trying to customize, and I'm not having a lot of luck.
There's so much in the FAQ list, I couldn't find anything to answer my question.
Here's what I have so far:
print "Content-type: text/plain","\n\n";
$up = `/usr/bin/uptime | cut -d " " -f 5-8`;
$uptime = `/usr/bin/uptime`;
($load_average) = ($uptime =~ /averages: ([^,]*)/);
print "The server has been up for ", $up , "and the load average is : ", $load_average , ".", "\n";
And here's the output:
The server has been up for day, 2:06, 1
and the load average is : 0.00.
I would prefer it say:
"The server has been up for 1 day, 2:06, and the load average is: 0.00"
All on one line.
There's 2 things wrong.
1st the $up variable isn't appropriate because that's going to change and the cut -f parameter won't handle it right. I need a regexp that finds everything between "up" and the second comma.
2nd Why is there a line feed after the output of the $up variable?
edit: I'm using perl 5.8.9 on FreeBSD 6.4-STABLE
Hope all that's clear, and thanks in advance for any advice.
Using Perl since 4/12/09
perl 5.8.9, FreeBSD 6.4-STABLE
(This post was edited by charlesD on Apr 12, 2009, 8:46 AM)