Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: [HOP] Working with Iterators, why do I suddenly get a coderef?

by choroba (Cardinal)
on Nov 03, 2013 at 00:42 UTC ( [id://1061001]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1061001]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2024-04-24 06:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found