Results 1 to 3 of 3
Hello everyone
I'm trying to print the uptime of a computer. First, I split the time at : and put it in an array:
Code:
my @time = split(/:/, $uptime);
...
- 03-31-2009 #1Linux User
- Join Date
- Jul 2007
- Location
- Greece
- Posts
- 277
the print command
Hello everyone
I'm trying to print the uptime of a computer. First, I split the time at : and put it in an array:
Then I simply print it:Code:my @time = split(/:/, $uptime);
The output I get is:Code:$t=print ("@time[0]hours and @time[1]min"); print $t;
20hours and 25
min
I don't understand why min is not on the same line as the rest of the string. I haven't included \n anywhere. Why is it printing min in a new line?
Can anyone please explain to me what I'm doing wrong?
Thank you
- 03-31-2009 #2
So first off, I have no idea what programming language you're using, so I'm a bit confused.
But anyway, where did you get the value in $uptime? What I suspect is happening is that $uptime stores the value "HH:MM\n". Then, when you split on the ':', the newline ends up in the second part when you print.
Your code looks somewhat Perl-like (though if it's Perl, you're using "print" wrong), and Perl has a function called "chomp" which specifically removes newlines from the end of strings. Otherwise, some more information would be helpful.DISTRO=Arch
Registered Linux User #388732
- 03-31-2009 #3Linux User
- Join Date
- Jul 2007
- Location
- Greece
- Posts
- 277
Hi Cabhan,
Sorry for not mentioning the programming language but you guessed it right.
You are correct, I just chomped $time[1] and is working fine now.
Thanks a lot for your reply.


Reply With Quote