Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

(dkubb) Re: (2) count phantom (using bind_columns)

by dkubb (Deacon)
on Mar 27, 2001 at 08:54 UTC ( [id://67428]=note: print w/replies, xml ) Need Help??


in reply to count phantom

Here's another way to do it, but using bind_columns and fetch which is the fastest way to fetch rows from the database, according to the DBI docs, and confirmed by recent benchmarks:

my $statement = q{ SELECT column FROM table }; my $sth = $dbh->prepare($statement); $sth->execute; my %hash; $sth->bind_columns(\my $column); ++$hash{$column} while $sth->fetch;

Although, it's really too bad you didn't use a database for the counting, what you want is possible with regular SQL:

my $statement = q{ SELECT column , COUNT(*) FROM table1 GROUP BY column }; my $sth = $dbh->prepare($statement); $sth->execute; my %hash; $sth->bind_columns(\my($column, $count)); $hash{$column} = $count while $sth->fetch;

If you have a large amount of information to walk through, it could be significantly faster to offload this sort of work to the database. It can do all sorts of internal optimizations, such as counting it's index, that you can't match with pure perl.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-24 11:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found