Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I'm getting an array reference from DBI like this:

my $arrayRef = $sth->fetchall_arrayref;

I want to find the number of rows returned, how do I do this?

I know I could do $sth->rows and get it but I'd be doing it over 600,000 times and don't want to add the extra stuff to the DB, just counting the array's in my array ref would do better.
  • Comment on Counting Number of Arrays in an Array Reference

Replies are listed 'Best First'.
Re: Counting Number of Arrays in an Array Reference
by Zaxo (Archbishop) on Oct 30, 2005 at 03:00 UTC

    $arrayRef is a genuine array reference, with one element per row. An array in scalar context evaluates to the number of elements, so just dereference in scalar context:

    my $rows = @{$arrayRef};

    After Compline,
    Zaxo

Re: Counting Number of Arrays in an Array Reference
by pg (Canon) on Oct 30, 2005 at 02:45 UTC