| August 1999 | Return to the Perl Hardware Store | Slide #34 |
sub mingle {
my @iterator = @_;
my $next = 0;
sub {
my $line = $iterator[$next]->();
$next = ($next + 1) % @iterator;
$line;
}
}
Now if you have several iterators you can turn them into one:
$new_it = mingle($it1, $it2, $it3);
(Proper handling of EOF conditions is left as an exercise.)
| Next | ![]() |
Copyright © 1999 M-J. Dominus |