in reply to Ghostly subroutine variables haunting me in subsequent calls

Add use strict;to your code and it will tell you why.

Specifically, the array that you use to return the results of your function to the caller @pileofinchis is never declared lexically (with my), and so you are (re-)using the same global array each time you call the function. As you only ever add values to the array

push @pileofinchis,$localinchi;

The contents of the array are added to, but never removed, each time you call it.

use strict catches these things for you and saves much time.


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.

Replies are listed 'Best First'.
Re^2: Ghostly subroutine variables haunting me in subsequent calls
by blazar (Canon) on Oct 25, 2005 at 17:40 UTC
    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...

      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.