in reply to Recursive method calls and references

You got typos, test_b recurses into test_a, never test_b
  • Comment on Re: Recursive method calls and references

Replies are listed 'Best First'.
Re^2: Recursive method calls and references
by Anonymous Monk on Jul 28, 2012 at 09:03 UTC

    The problem is ## HELLO

    $ perl -MO=Deparse,-p grimy sub test_a { use warnings; use strict 'refs'; (my $arg = shift()); (ref($arg) ? $$arg->test_a([0]) : $arg); ## HELLO } sub test_b { use warnings; use strict 'refs'; (my $arg = shift()); (ref($arg) ? test_a($$arg[0]) : $arg); } use warnings; use strict 'refs'; test_b([42]); test_a([42]); grimy syntax OK

    The problem is indirect object syntax, to fix you need a forward declaration ( sub test_a; ) or parenthesis

      Thanks for your answer :)
Re^2: Recursive method calls and references
by Grimy (Pilgrim) on Jul 28, 2012 at 09:03 UTC
    Nope, I don't have typos, and nope, test_b doesn't 'recurse', it just calls test_a. Only test_a is recursive, and only test_a crashes, which is why I assumed that it is the recursivity that causes problems, as you can read in my first post.