Okay, so those two subs are exactly identical, yet one runs just fine and the other crashes. My only guess is that the recursive nature of test_a somewhat has an impact on the context given to the reference. Adding parentheses around $$arg[0] fixes that alright, but I don't care. I just want to understand.use strict; use warnings; sub test_a { my $arg = shift; ref($arg) ? test_a$$arg[0] : $arg } sub test_b { my $arg = shift; ref($arg) ? test_a$$arg[0] : $arg } print test_b[42]; # prints '42' print test_a[42]; # dies 'Not a SCALAR reference at test line 3
In reply to Recursive method calls and references by Grimy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |