CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Re: [g4143] Perl TextFilter to turn clock format ( 01:36:30 ) into seconds ( 5790 ): Edit Log



recruiter
User

May 4, 2013, 6:20 PM


Views: 277
Re: [g4143] Perl TextFilter to turn clock format ( 01:36:30 ) into seconds ( 5790 )

From what I understood from your post, your file is already formatted as <t>00:00:00</t> ?

If this is the case, here is an example of how you can read in the data and convert the hh:mm::ss -> seconds.

Sample times.txt file:


Code
<t>00:01:39</t>    
<t>00:02:39</t>
<t>00:03:39</t>
<t>00:04:39</t>
<t>00:05:39</t>
<t>00:06:39</t>



You could use File::Slurp to read in your file, you can find the documentation on CPAN.


Code
use strict;   
use warnings;

use File::Slurp qw( read_file );

my @data = read_file('times.txt' {chomp =>1});

my @times =
map {
my($h,$m,$s) = split /:/, $_;
$h*3600+$m*60+$s
} @data;

print "$_\n" for (@times);



(This post was edited by hwnd on May 4, 2013, 7:11 PM)


Edit Log:
Post edited by recruiter (User) on May 4, 2013, 6:49 PM
Post edited by recruiter (User) on May 4, 2013, 6:50 PM
Post edited by recruiter (User) on May 4, 2013, 7:11 PM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives