# Usage: my $iter = DbiSthIterator->new($sth1, $sth2, ...); # # while ($row = $iter->next()) { # ...undef signals the exhaustion of the iterator # } package DbiSthIterator; sub new { my ($class, @sth) = @_; bless \@sth, $class; } sub next { my $self = shift; while (my $sth = shift(@$self)) { if (my $row = $sth->fetchrow_hashref()) { push(@$self, $sth); return $row; } else { # Leaving the exhausted $sth out of the queue next; } } undef; } 1;