in reply to Re: Ghostly subroutine variables haunting me in subsequent calls
in thread Ghostly subroutine variables haunting me in subsequent calls

Add use strict; to your code and it will tell you why.
This is not 100% sure: @pileofinchis may be declared in a lexical scope enclosing the sub definition. In which case he may even desire to actually push into it. But then I see no reason to return a reference to it as well, and I'd be curious to know what he is doing with it...

Replies are listed 'Best First'.
Re^3: Ghostly subroutine variables haunting me in subsequent calls
by BrowserUk (Patriarch) on Oct 25, 2005 at 18:32 UTC

    True, but if the OP is deliberately creating a closure, then he probably wouldn't be asking the question.

    Even then, use strict (or maybe -w, I use both so I'm never quite sure which is giving me the information), would still be a good idea as it might well warn him of an even deeper and more obscure problem in the event that the closure is not knowingly deliberate:

    sub outer{ my @a; sub inner{ push @a, 1; return \@a; } return 1 };; Variable "@a" will not stay shared at (eval 3) line 1, <STDIN> line 1.

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.