
Laurent_R
Veteran
/ Moderator
Dec 11, 2012, 8:15 AM
Post #2 of 2
(1454 views)
|
Re: [x13] print returned strings from subroutines
[In reply to]
|
Can't Post
|
|
Your subroutine is not really doing anything, as you compute a string but don't do anything with it. Although it should work, it would be more explicit to do something like this:
sub getFriendlyUptime { my $duration = int($_[0]/(24*60*60)) . "d:" . ($_[0]/(60*60))%24 . "h:" . ($_[0]/60)%60 . "m"; return $duration; } Then, print $fuptime to see what you get, if the conversion if OK. Then, I am not sure what you are trying to do with:
push(@vals, [8, $fuptime]) Why do you want to push an anonymous array with a constant value (8) into the @vals array? This is correct syntax, but probably does not do what you want. If you want to set the array element with subscript 8, then you should do: if you just want to store your value in the array, then: But if you use:
push(@vals, [8, $fuptime]) then, to retrieve $fuptime, you need something like $vals[0][1] (while $vals[0][0] will contain '8'). I doubt that's what you want.
|