adamsj has asked for the wisdom of the Perl Monks concerning the following question:
However, when I sweeten the function as suggested in the text:# This software is Copyright 2005 by Elsevier Inc. You may use it # under the terms of the license at http://perl.plover.com/hop/LICENSE +.txt . ### ### upto ### ## Chapter 4 section 2.1 sub upto { my ($m, $n) = @_; return sub { return $m <= $n ? $m++ : undef; }; } my $it = upto(3,5); my $value->it(); print "$value\n";
I get a failure: Undefined subroutine &main::3 calledsub upto { my ($m, $n) = @_; return Iterator { return $m <= $n ? $m++ : undef; }; } sub Iterator (&) { return $_[0]; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Basic question about Iterator code
by choroba (Cardinal) on May 12, 2025 at 14:18 UTC | |
Re: Basic question about Iterator code
by ikegami (Patriarch) on May 12, 2025 at 23:15 UTC |