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.


In reply to Re: how to determine of fetchrow_Arrayref is empty? by doom
in thread how to determine of fetchrow_Arrayref is empty? by poolboi

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.