Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^2: hash refferences

by leonidlm (Pilgrim)
on Aug 21, 2008 at 12:36 UTC ( [id://705777]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://705777]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2024-04-16 04:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found