in reply to Re: The weirdest problem with undef
in thread The weirdest problem with undef

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

Replies are listed 'Best First'.
Re^3: The weirdest problem with undef
by davorg (Chancellor) on Dec 22, 2004 at 10:22 UTC

    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
        EVERYBODY: thanks for your replies, i changed the my (@source,@destination) into local (@source,@destination) and now it works like it should.

        so thanks again for this simple lesson..
        --
        to ask a question is a moment of shame
        to remain ignorant is a lifelong shame