Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^2: processing timelog

by sandy105 (Scribe)
on Aug 24, 2014 at 11:29 UTC ( [id://1098454]=note: print w/replies, xml ) Need Help??


in reply to Re: processing timelog
in thread processing timelog

the total time is almost figured out ; i cant seem to think of a way to get process time without writing inefficient & repetitive code :(

Replies are listed 'Best First'.
Re^3: processing timelog
by Anonymous Monk on Aug 24, 2014 at 11:45 UTC

    the total time is almost figured out ; i cant seem to think of a way to get process time without writing inefficient & repetitive code :(

    Congratulations, you are about to start programming, start naming subroutines, subroutines that take arguments and return values, and die on critical errors (like can't open file), subroutines with meaningful names that make sense in the context of your application, subroutines whose names are part of your application vocabulary/glossary

    perlintro#Writing subroutines and http://learn.perl.org/books/beginning-perl/ Chapter 8: Subroutines

      i know and i have used subroutines , and i am writing subroutines for converting datetime to proper time , but cant figure out how to add up the process time

      right now i am calculating total time separately and individual times by appending each process time to an hash with id as key and then consolidating ..i just cant figure out a elegant way that's it.thats why asked for help .any ideas or pseudocode would help

Re^3: processing timelog
by poj (Abbot) on Aug 24, 2014 at 20:41 UTC
    Consider using a database perhaps ?
    #!perl use strict; use warnings; use DBI; #create db my $dbfile = 'database.sqlite'; unlink($dbfile); my $dbh = DBI->connect('dbi:SQLite:dbname='.$dbfile , undef , undef , {RaiseError =>1, AutoCommit =>0}) or die $DBI::errstr; $dbh->do('CREATE TABLE DATA (F1 datetime,F2 INTEGER,F3,F4)'); $dbh->do('CREATE TABLE STARTED (F1 datetime,F2,F3)'); $dbh->commit; # load data my $sth = $dbh->prepare('INSERT INTO DATA VALUES (?,?,?,?)'); while (<DATA>){ chomp; my @f = split ','; if (@f==4){ $sth->execute(@f); } else { print "Input Line $. Skipped : $_\n"; } } $dbh->commit; # select started records $dbh->do("INSERT INTO STARTED SELECT F1,F2,F3 FROM DATA WHERE F4 LIKE '%started%'"); $dbh->commit; # calculate duration from start my $ar = $dbh->selectall_arrayref(" SELECT D.F1,D.F2,D.F3,D.F4, (1000*strftime('%s',D.F1))+D.F2 - (1000*strftime('%s',S.F1))-S.F2 FROM DATA AS D LEFT JOIN STARTED AS S ON D.F3 = S.F3"); for (@$ar){ printf "@$_\n"; } $dbh->disconnect; __DATA__
    poj

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1098454]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2024-04-24 09:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found