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

But this still isn't doing what you are expecting. Not declaring those two variables would produce the same result (given the amount of code you have given). A local block is making a local copy of those global variables for use inside the block, but you are altering and accessing both variables outside of the block... It may behave as you expect, but it isn't doing what you think it is.

Update: When I said copy, I didn't mean the global values are retained. Wrong use of the word. I meant 'reset for use inside of the block.'

Replies are listed 'Best First'.
Re^7: The weirdest problem with undef
by davorg (Chancellor) on Dec 22, 2004 at 15:39 UTC
    A local block is making a local copy of those global variables in the block, but you are altering and accessing both variables outside of the block...

    Er... there is only every one copy of each package variable. "local" resets the value of a variable (whilst storing away the existing value for reuse later). Therefore it doesn't matter where you access the variable. Until you exit the block containing the "local" call, you will always get the "localised" version.

    --
    <http://www.dave.org.uk>

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

Re^7: The weirdest problem with undef
by insaniac (Friar) on Dec 22, 2004 at 14:41 UTC
    ah ok.. i'll read some doc again then about the local thing, but i thought it was helping me..

    and eventually i rewrote the code into:

    my ($source, $destination) = get_elements ; scan_matrix $mode, $source, $destination;
    in the loop... where $source and $destination are references to arrays...

    what amazes me about perlmonks is: jeeeez, long after this problem is solved (for me), ppl keep experience-- me. so, it's not allowed to ask beginnersquestions without being degraded in your status (i mean: okay, i made a mistake... but does EVERYBODY need to degrade my status?)? hm...
    makes me think twice before i ask anything on this forum.
    /me crawls back in his cave...

    --
    to ask a question is a moment of shame
    to remain ignorant is a lifelong shame

      You're getting downvoted because you made a quick hacky fix. You knew it was a quick hacky fix when you made it but you still went ahead. And you implied that you thought it would be too much effort to fix your script to work under "strict" and "warnings".

      Take a look at the Pragmatic Programmers' list of tips. Right near the top you'll see "don't live with broken windows". You sounded like you were happy to live with broken windows and a lot of people round here disapproved of that.

      So you're not getting downvoted because you asked a beginner question. You're getting downvoted because you strongly implied that you're not a beginner but you weren't prepared to make the correct fix. It sounds like you've now made a start on doing the right thing so you can expect to get some more positive votes.

      --
      <http://www.dave.org.uk>

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

        thanks again ;-) and i had to do the quick fix, because it was really urgent (as in: not for fun, but business) and rewriting takes much much more time.
        BUT, i've started rewriting that script since this thread here... so, ok, the downgrade in point motivated me in doing it better...

        damn, i really sounded like a small child that didn't get enough sugar huh ... truely i have much too learn.
        so ... my apologies, and thanks.
        --
        to ask a question is a moment of shame
        to remain ignorant is a lifelong shame
      It is much more important to learn around here than to gain experience. I would continue to post. You'll be glad you did in the long run.