bnj.s wrote:
Hello,
I have a file with lots of times in the format "01:22:33,456", where the
numbers after the comma represent the milliseconds.
I would like to reduce all these times by a given offset. I first
thought to convert the string to a sort of date format, and then to do a
minus operation, and then to convert the result back to a string of the
original form. However, I have great difficulties finding how to handle
times and dates. I am sure, however, that there exist a simple way to do
so in perl. Could you please help me and tell me how you would do it?
Thank you and best regards,
Benjamin
Unless I don't quite get what you're asking this seems pretty simple
# string to milliseconds
$refTime = "01:22:33,456"; #as in your example
$refTime =~ /(\d+):(\d+):(\d+),(\d+)/; #capture the elements and assign
$hours = $1;
$minutes = $2;
$secs = $3;
$mili = $4;
#calc milliseconds if needed
$millisec = $mili+($secs*1000)+($minutes*60*1000)+($hours*60*60*1000);
#reduce minutes by 5
$minutes-= 5;
#format for printing
$outStr = sprintf("%02d:%02d:%02d,%03d",$hours,$minutes,$secs,$mili);
print $outStr;
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>