Print

Print


On Fri, 2007-10-12 at 08:13 -0400, Mauricio Tavares wrote:
> 	What would be the best way to convert time given in a 12h clock
> (as in 12:52 AM) format into 24h clock (00:52) using perl? I have a file
> full of data which was recorded in that format and would like to convert
> it to the 24h style...
> 
> ...unless there is a clever way to feed that right into gnuplot. ;)

Well, I wouldn't say it's the *best* way, and I'd still recommend the
cpan module...

But if you want brute force, this seems to work OK.  :)

while(<>)  {
    s/(\d+):(\d+) ([AP]M)/$1%12+(12*($3 eq "PM")).":$2"/e;
    s/(\d):/0$1:/;
    print;
}


-- 
John Gelnaw <[log in to unmask]>
CITS, McKnight Brain Institute