my $sth = $dbh->prepare($stmt); $sth->execute(); my $header = 0; while (my $row = $sth->fetchrow_hashref) { print "Here is list of IDs:\n" if !$header++; print "$row->{id}\n"; }
Alternative:
my $sth = $dbh->prepare($stmt); $sth->execute(); my $row = $sth->fetchrow_hashref; print "Here is list of IDs:\n" if $row; while ($row) { print "$row->{id}\n"; $row = $sth->fetchrow_hashref; }
Simplified code due to memory:
my $ids = $dbh->selectcol_arrayref($stmt); if (@$ids) { print "Here is list of IDs:\n"; print "$_\n" for @$ids; }
source share