in reply to Basic question about Iterator code

You probably meant
my $value = $it->();

instead of

my $value->it();
in the first sample.

As for the error: in order to use the block syntax with a (&)-prototyped subroutine, you need to declare the subroutine before you use it. Move the last line to the top of the second sample and everything should work.

#!/usr/bin/perl use warnings; use strict; use feature qw{ say }; sub Iterator(&) { $_[0] } sub upto { my ($m, $n) = @_; return Iterator { $m <= $n ? $m++ : undef } } my $it = upto(3,5); while (my $value = $it->()) { say $value; }

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]