in reply to how to determine of fetchrow_Arrayref is empty?

fetchrow_arrayref returns a defined reference only if there are rows in the result set, if not it's undefined. So you just need to replace the "while" with something like
if ( not( $ref ) ) { print "No results\n"; } else { # code to print results }

If I may offer some observations about the way you're doing this:

(1) The variable $numFields would be better named $number_fields. See perlstyle. And you might want to change "$ref" to "$aref" to indicate what kind of reference it is (myself, I'd probably call it $row, though I think Conway prefers $row_ref).

(2) The C-style for loop over the fields might be clearer if done in a more perl like way, just for example:

my $result = join ", ", @{ $ref }; print $result, "\n";

(3) Personally I lean towards fetchrow_hashref these days: the performance penalty on that was fixed a long time ago.

Replies are listed 'Best First'.
Re^2: how to determine of fetchrow_Arrayref is empty?
by ysth (Canon) on May 27, 2008 at 09:22 UTC
    fetchrow_hashref wouldn't work with what the OP is doing for each row (at least, not without a lot of hassle).

      The OP hasn't actually made the ultimate goal clear -- my guess would be that a comma separated list of all fields is just an intermediate step while learning how to use DBI.

      Starting with fetchrow_hashref and using a stub like this is probably a better place to begin:

      foreach my $field_name (keys %{ $row_href }) { my $value = $row_href->{ $field_name }; print "$field_name: $value \n"; }

      And if the order of the fields is important, you can replace keys %{ $row_href } with an array @field_names... typically, you have that information already, since you need it to build the SELECT.