in reply to The weirdest problem with undef

Your code can't possibly be doing what you think it's doing. my variables are lexically scoped, which means they can't be seen outside the block of code they are delcared in. Thus, get_elements can't possibly be filling the arrays

Dave.

Replies are listed 'Best First'.
Re^2: The weirdest problem with undef
by insaniac (Friar) on Dec 22, 2004 at 10:13 UTC
    believe me: they get filled. the really get filled, because 99% of the time the scripts works perfectly.
    --
    to ask a question is a moment of shame
    to remain ignorant is a lifelong shame

      I assume you're saying that because you're accessing the data again in "scan_matrix". So here's what's really happening.

      1. Each time round the loop new lexical variables are created by the "my" call.
      2. You then call "get_elements" which puts data into the _package_ variables called @source and @destination, _not_ the lexical variables that you have created.
      3. You then call "scan_matrix" which also accesses the _package_ variable versions.
      4. You then use "undef" in your main loop which effects the _lexical_ versions of the variables.
      5. The loop ends and your lexical variables go out of scope and are destroyed. The package variables, however, still exist and still contain the data that "get_elements" put in them.
      6. The loop executes again and the process repeats.
      --
      <http://www.dave.org.uk>

      "The first rule of Perl club is you do not talk about Perl club."
      -- Chip Salzenberg

        dave, many thanks for this clarification... i obviously made a big mistake! i'll test it now...
        --
        to ask a question is a moment of shame
        to remain ignorant is a lifelong shame