in reply to Re: hash references
in thread hash refferences

But whats the difference between the following:
1. Declaration of the %temp inside the loop
2. Performing: undef %temp at the end of each iteration
Someone ?

Replies are listed 'Best First'.
Re^3: hash refferences
by Corion (Patriarch) on Aug 21, 2008 at 12:40 UTC

    They are completely different. undef %temp empties the variable but still keeps the variable there, while a lexical variable goes out of scope. The undef %temp acts on the values, while leaving the scope acts on the binding of the name to the value.

Re^3: hash references
by moritz (Cardinal) on Aug 21, 2008 at 12:53 UTC
    What Corion said is right.

    %temp is actually a container - think of a bucket. You can fill this container (putting water into the bucket), and empty it, which is what %temp = undef does.

    Or you can but your bucket into the cupboard, (pushing it to an array), and take a new bucket (declaring %temp inside the loop).

    In this real-world analogy you can see that there's a huge difference between these two things.

      which is what %temp = undef does. No, thats what undef %temp does, big difference