2 ms·
Not really. As ~btilly suggested in another post, perl really doesn't have anything like it. The closest thing that exists is using a code reference. sub
by simcop2387 13y ago
Not really. As ~btilly suggested in another post, perl really doesn't have anything like it. The closest thing that exists is using a code reference.
sub new_iter {
my $i = 0;
return sub {$i++}
}
my $iter = new_iter();
while(my $number = $iter->()) {
say $number;
}
This is of course a trivial example, but it does give a bit of an idea of the only way Perl has to be able to implement them, essentially anonymous functions and closures. This is useful, but it doesn't make it easy to take say a red-black tree, and iterate over the entire set of values in it (though with higher level languages like perl, you probably wouldn't implement much with a red-black tree, maybe a k-tree would be better?)