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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

converting milliseconds back to time 1

Status
Not open for further replies.

sapatos

Programmer
Jan 20, 2006
57
AU
My programme scans a series of files which contain the following time data:

hr:mi:ss:milsec
line 1=00:14:42:321
line 2=00:00:08:313
line 3=00:00:33:766

I have broken this down to milliseconds in order to calculate various avg/mode/std deviation etc.

line 1=882321
line 2=8313
line 3=33766

I want to return this to the original format for display purposed but I'm having difficulties. Can anyone suggest a method for this? i'm unable to use modules ;(
 
Code:
sub msec_format{
  use integer;
  my($sec,$min,$hr);
  my($msec)=@_;
  $sec=$msec/1000;
  $msec-=$sec*1000;
  $min=$sec/60;
  $sec-=$min*60;
  $hr=$min/60;
  $min-=$hr*60;
  return sprintf("%02d:%02d:%02d:%03d",$hr,$min,$sec,$msec);
}

Franco
: Online engineering calculations
: Magnetic brakes for fun rides
: Air bearing pads
 
thanks franco, thats definitely one for the toolbox ;)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top