in reply to Recursive method calls and references
Adding parentheses around $$arg[0] fixes that alright, but I don't care.
But you should care. If adding parenthesis helps, it's a parsing problem. Here's what B::Deparse has to say to the code:
sub test_a { use warnings; use strict; my $arg = shift(); ref $arg ? $$arg->test_a([0]) : $arg; } sub test_b { use warnings; use strict; my $arg = shift(); ref $arg ? test_a($$arg[0]) : $arg; }
So the call to test_a inside test_a is parsed as indirect method call syntax. Why? Because it's not predeclared. In Perl 5, a name only becomes visible in the statement after the declaration, which is why you can't write
my $sub = sub { ...; $sub->(); .. };
So, in test_b you call test_a, which has already been declared. So either use parens after the function name, or predeclare it with
sub test_a; sub test_a { ...; recurse into test_a here };
|
---|
In Section
Seekers of Perl Wisdom