Class::DBI::Iterator(3) - User Contributed Perl Documentation
Class::DBI::Iterator - Iterate over Class::DBI search results
| Use Case | Command | Description |
|---|---|---|
| 🔍 Searching | my $it = My::Class->search(...) | Execute search in scalar context to get an iterator |
| 🔢 Counting | $it->count | Get the number of results |
| 🏁 First result | $it->first | Retrieve the first result |
| 🔄 Iterating | while ($it->next) { ... } | Loop through results one at a time |
| ✂️ Slicing | $it->slice(10,19) | Get a range of results (list or arrayref) |
| 🔄 Reset | $it->reset | Reset the iterator to the beginning |
| 🗑️ Delete all | $it->delete_all | Delete all results from the database |
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.
Generated by phpman v4.9.26-5-g7740029 Author: Che Dong Under GNU General Public License
2026-08-14 21:13 @2600:1f28:365:80b0:4d23:66fa:c2bb:7bae
CrawledBy CCBot/2.0 (https://commoncrawl.org/faq/)