in reply to How to use undef in DBI sql query result collection
If what you want is to pull the set of data from the database, it would be slightly (by not much) faster to do this:
# Error handling assumed. my $sql = " ... "; my $sth = $dbh->prepare_cached( $sql ); $sth->bind_columns( \(my ($foo)) ); my @data; while ($sth->fetch) { push @data, $foo; } $sth->finish;
The reason is that Perl doesn't have to allocate and deallocate return values - the data is placed right into the scalar reference you passed bind_columns(). A similar method can be used for your HoA in the third snippet. You can, alternatively, do:
# Error handling assumed. my $sql = " ... "; my $sth = $dbh->prepare_cached( $sql ); my @stuff; $sth->bind_columns( \(my ($foo), @stuff[0..3]) ); my %data; while ($sth->fetch) { $data{$foo} = [ @stuff ]; } $sth->finish;
Now, the alternatives I'm presenting won't double your throughput. We're talking, at best, maybe 5-10%, if that. Most applications will see a 0-2% improvement. The guarantee is that this isn't slower and it might be faster.
Being right, does not endow the right to be rude; politeness costs nothing.
Being unknowing, is not the same as being stupid.
Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.
|
|---|