# offset is how many records into the dataset to start, # 0 means start at the beginning # count is how many records to read # This returns an arrayref to an arrayref corresponding # to the values for each row. You will only get at most # count rows returned, but may get less if there is less # data than requested sub get_data_from_db { my ($offset, $count, $dbh) = @_; my $sth = $dbh->prepare( qq(SELECT whatever FROM TABLE_FOO )); $sth->execute; my @results; while ($row = $sth->fetchrow_arrayref and $count-- > 0) { if ($offset > 0) { $offset--; $next; } push @results, $row; } $sth->finish; return \@results; }