in reply to Re^3: sub calls and memory use
in thread sub calls and memory use

You pass arguments in @_, as always.

So I was just using the wrong global variable! I can see now that pushing my arg into @_ before the &sub call prevents memory growth. Thank you Corion.

Replies are listed 'Best First'.
Re^5: sub calls and memory use
by LanX (Saint) on Nov 16, 2019 at 15:03 UTC
    In Perl you are generally better off translating tail calls to loops. They are way faster and easier to understand.

    You never explained your use case, but your example is easily translated with redo

    Concerning your memory growth, we'd need to know how you declared the "global var".

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

      In Perl you are generally better off translating tail calls to loops.

      I replaced that recursive sub with a while loop and yeah, makes more sense, less code, and no memory bomb. ThanX

      Concerning your memory growth, we'd need to know how you declared the "global var".

      Sorry I was mistaken about that :-/