Re: anyway to determine # rows before fetch loop ends and without seperate count(*)



Also very convoluted, all of that can be done with:

my $results = $dbh->selectall_arrayref($sql); # if you only want to process a certain amount just LIMIT in your $sql...


I appreciate the response. I tested selectall_arrayref and as I expected, irregardless of the number of rows returned, $results will always point to a matrix. So from what I am seeing, $record->[0] as

Actualyy its an array reference and each element of the array is an array refernce that is the dat areturned by the select.


you have written below would have to be written as $record[0]->[0]. At

nope. $record is one element of the $results array in the for loop,look again:


this point I've come to conclusion that my requirements are causing uneccessary complications. If it wasn't clear, previously I was wanting the data from a sql statement with one row returned to be stored into an array of columns, otherwise make it an array of columns and rows.....

Sounds like you want selectall_arrayref() still... did you read it documentation?



my $results = $dbh->selectall_arrayref("SELECT id, foo, bar FROM baz WHERE $where");


my $count = @{ $results }; # the number of elements in $results (IE the number of rows returned)

for my $record (@{ $results }) { # go through each $record in your $results
    print "Id $record->[0] has a foo of $record->[1]\n";
    print "Id $record->[0] has a bar of $record->[2]\n";
}

I'll simply go with a matrix always and be done with it.

There's no "matrix" :) you're making it too complex on yourself :)

You have an array ref that you can get the number of rows from *and* each record from as an array ref itself, its not nearly as complicated or obscure as a "matrix".

my $count = @{ $results };

$dbh->disconnect;

if($count < 1000) { # or whatever you wanted teh count for...
   for my $record(@{ $results }) {
       # now use the data:
       # $record->[0]
       # $record->[1]
   }
}






.



Relevant Pages

  • Re: Fwd: Re: dbm again
    ... The hash has only one key, ... Can't use string ) as an ARRAY ref while strict refs in ... It seems like I am somehow dealing with a reference to an array!? ... as a string and tried to be derefenced. ...
    (perl.beginners)
  • Re: Help with HoH and accessing right keys
    ... keys, put an array ref. ... When you see a start tag, create a new array ...
    (comp.lang.perl.misc)
  • Re: Help with HoH and accessing right keys
    ... keys, put an array ref. ... When you see a start tag, create a new array ...
    (comp.lang.perl.misc)
  • Re: Help with HoH and accessing right keys
    ... keys, put an array ref. ... When you see a start tag, create a new array ...
    (comp.lang.perl.misc)
  • Re: Array as instance variable
    ... >> are the most common and usually direct way to do perl objects. ... just the same as with any array you need to ... and even if he uses a hash ref for the object and it has the array ref, ... constant) expressions and it is a very old coding and compiling ...
    (comp.lang.perl.misc)