El código del constructor iterator
retorna la subrutina de iteración.
Esta última controla el agotamiento
de la lista en la línea 9.
En tal caso se vuelve a iniciar el
contador ($next = $from-$step)
y se retorna undef (obsérvese el 
uso de la coma).
lhp@nereida:~/Lperl/src$ cat -n iterators.pl
 1  use strict;
 2
 3  sub iterator {
 4    my ($from, $to, $step) = @_;
 5    $step = 1 unless defined($step);
 6    my $next = $from-$step;  # iniciar contador
 7    my $closure_ref = sub {
 8      $next += $step;
 9      $next = $from-$step, return if $next > $to;
10      $_[0] = $next;
11      return 1;
12    };
13    return $closure_ref;
14  }
Casiano Rodríguez León
