Class::DBI::Iterator(3pm) User Contributed Perl Documentation Class::DBI::Iterator(3pm)
Class::DBI::Iterator - Iterate over Class::DBI search results
| Use Case | Command | Description |
|---|---|---|
| Count results | $it->count | Returns the number of items in the result set |
| Get first result | $it->first | Returns the first object from the iterator |
| Iterate through results | while ($it->next) { ... } | Fetches and processes each result one at a time |
| Get a slice of results | $it->slice(10,19) | Returns a range of results (10th through 19th) |
| Reset iterator | $it->reset | Resets the iterator to the beginning of the result set |
| Delete all results | $it->delete_all | Deletes all objects matched by the search |
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;
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.
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.
perl v5.32.0 2020-12-28 Class::DBI::Iterator(3pm)
Generated by phpman v4.10.0-7-g98e9fd5 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-08-31 08:26 @216.73.217.135
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)