# man > Class::DBI::Iterator

---
type: CommandReference
command: Class::DBI::Iterator
mode: perldoc
section: 3pm
source: perldoc
---

## Quick Reference
- `$it->count` — returns number of results
- `$it->first` — returns first result
- `$it->next` — iterates to next result
- `$it->slice(10,19)` — returns a slice of results
- `$it->reset` — resets the iterator to start
- `$it->delete_all` — deletes all results

## Name
Class::DBI::Iterator - Iterate over Class::DBI search results

## Synopsis
perl
my $it = My::Class->search(foo => 'bar');
my $results = $it->count;
my $first_result = $it->first;
while ($it->next) { ... }
my @slice = $it->slice(10,19);
my $slice = $it->slice(10,19);
$it->reset;
$it->delete_all;
## Description
Any Class::DBI search (including a has_many method) which returns multiple objects can be made to return an iterator instead simply by executing the search in scalar context. Then, rather than having to fetch all the results at the same time, you can fetch them one at a time, potentially saving a considerable amount of processing time and memory.

**CAVEAT**: Note that there is no provision for the data changing (or even being deleted) in the database inbetween performing the search and retrieving the next result.