in reply to [Solved][HOP] Working with Iterators, why do I suddenly get a coderef?

I am not sure I understand the question, but adding more parentheses might change the results you get. You can use B::Deparse (used by Data::Dumper in your code, anyway) to see how Perl adds the parentheses to your code. For example, in "Invalid append 1", the following line
my $it3 = append(upto(1,3), list_iterator( qw(foo bar baz)), upto (7,9 +));

changes the output to

Invalid append 1 $VAR1 = 1; $VAR1 = 2; $VAR1 = 3; $VAR1 = 'foo'; $VAR1 = 'bar'; $VAR1 = 'baz'; $VAR1 = 7; $VAR1 = 8; $VAR1 = 9;
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: [HOP] Working with Iterators, why do I suddenly get a coderef?
by three18ti (Monk) on Nov 03, 2013 at 01:08 UTC

    Hello,

    Thanks for your reply. Interestingly, I'm not getting a different result when adding parenthisis for the append() call, but when I use parenthesis for the call to list_iterator, it DOES fix my problem.

    my $it3 = append (upto(1,3), list_iterator qw(foo bar baz), upto (7,9) +); print_it $it3;

    prints:

    Invalid append 1 $VAR1 = 1; $VAR1 = 2; $VAR1 = 3; $VAR1 = 'foo'; $VAR1 = 'bar'; $VAR1 = 'baz'; $VAR1 = sub { use warnings; use strict 'refs'; return $start <= $end ? $start++ : undef; };

    But when I use parenthesis around list_iterator:

    print "\n\nInvalid append 1\n"; my $it3 = append upto(1,3), list_iterator (qw(foo bar baz)), upto (7,9 +); print_it $it3;

    I get what I would expect

    Invalid append 1 $VAR1 = 1; $VAR1 = 2; $VAR1 = 3; $VAR1 = 'foo'; $VAR1 = 'bar'; $VAR1 = 'baz'; $VAR1 = 7; $VAR1 = 8; $VAR1 = 9;

    Thanks for the assist! I think the problem is trying to make too many calls to subs without parenthesis.