[Classiccity-pm] timtowtdi

Darrell Golliher darrell at golliher.net
Wed Sep 29 13:08:05 CDT 2004


I'm interested in seeing out other people would do something.  I have
a solution I like, it's at the end.

The problem:  You have parsed out an uptime string from the web
interface of a network device.  The string is in this form:

	  "20 hours 5 minutes 34 seconds"

And here are some observations for different cases:

	 "1 hours 3 minutes 20 seconds"

	 "3 minutes 13 seconds"
	 
	 "25 seconds"

How would you parse that to properly populate these three variables:

    $hours
    $minutes
    $seconds

Here is my solution where $uptime is the starting string;

  my ($hours,$minutes,$seconds) = (reverse split /\s+/,  $uptime)[5,3,1];


cheers,

-Darrell


More information about the Classiccity-pm mailing list