Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: To find the no of occurenaces and max min value

by poj (Priest)
on Jul 14, 2014 at 10:42 UTC ( #1093525=note: print w/ replies, xml ) Need Help??


in reply to To find the no of occurenaces and max min value

You could consider using a database solution

#!perl use strict; use DBI; my $dbh = dbh('database.sqlite'); # input my $sth = $dbh->prepare('INSERT INTO DATA VALUES (?,?)'); while (<DATA>){ chomp; if ( /(select \* from \w+).*::(.*)/i ){ $sth->execute($1,$2); print "Data : [$1] [$2]\n"; } else { print "Skip : $_\n"; } } $dbh->commit; # report print '-'x55,"\n"; printf "%-20s %5s %5s %5s %5s %5s\n",('SQL','Count','Total','Min','Max +','Avg'); my $ar = $dbh->selectall_arrayref( 'SELECT F1,COUNT(F2),SUM(F2),MIN(F2),MAX(F2),AVG(F2) FROM DATA GROUP BY F1 ORDER BY F1'); for (@$ar){ printf "%-20s %5d %5d %5d %5d %5.1f\n",@$_; } close OUT; $dbh->disconnect; # create db sub dbh { my $dbfile = shift; unlink($dbfile) if (-e $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,F2 integer)'); $dbh->commit; return $dbh; } __DATA__ SQL :: select * from person ...etc , Time Taken :: 30 SQL :: select * from emp ...etc , Time Taken :: 5 SQL :: select * from home ...etc , Time Taken :: 20 SQL :: select * from emp ...etc , Time Taken :: 30 SQL :: select * from person ...etc , Time Taken :: 10 SQL :: select * from home ...etc , Time Taken :: 20 SQL :: select * from person ...etc , Time Taken :: 50
poj


Comment on Re: To find the no of occurenaces and max min value
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (19)
As of 2015-07-28 14:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (255 votes), past polls