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: [gregork] Perl TextFilter to turn clock format ( 01:36:30 ) into seconds ( 5790 ): Edit Log



g4143
Novice

May 4, 2013, 4:43 PM


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

I would try something like....


Code
#!/usr/bin/perl 

use warnings;
use strict;

while ( <DATA> )
{
chomp;
if ( /(\d\d):(\d\d):(\d\d)/ )
{
print "<t>", $1 * 3600 + $2 * 60 + $3, "</t>\n";
}
}

__END__
<t>00:01:39</t>
<t>01:36:30</t>


Or if you want to write the values to a new file...


Code
#!/usr/bin/perl 

use warnings;
use strict;

$^I = '.bak';

while ( <> )
{
s{(\d\d):(\d\d):(\d\d)}{$1 * 3600 + $2 * 60 + $3}e;
print;
}

__END__



(This post was edited by g4143 on May 4, 2013, 5:15 PM)


Edit Log:
Post edited by g4143 (Novice) on May 4, 2013, 4:47 PM
Post edited by g4143 (Novice) on May 4, 2013, 4:48 PM
Post edited by g4143 (Novice) on May 4, 2013, 5:15 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