in reply to Passing DBI resultset to function
Here's an untested example of how you go about passing a statement handle (resultset) to a subroutine.
my $sth = $dbh->prepare("MY SQL QUERY"); $sth->execute(); SimpleResultsDump($sth); sub SimpleResultsDump { my $SH = shift; my $cnt=0; while (my $hr = $SH->fetchrow_hashref()) { print ("-" x 40), " record: ", ++$cnt, "\n"; for my $k (sort keys %$hr) { my $v = "'$$hr{$k}'" // 'null'; print "Field $k holds: $v\n"; } } }
...roboticus
Error checking left as an exercise for the reader!
|
|---|