Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re^4: How to build a hash?

by Ben Win Lue (Friar)
on Apr 25, 2005 at 13:20 UTC ( #451178=note: print w/ replies, xml ) Need Help??

in reply to Re^3: How to build a hash?
in thread How to build a hash?

Sorry, maybe my use english is a bit confusing... 8-)
My problem was, I stored a reference to a hash (%hash_a) in a hash (%hash_b). Worked perfectly for one record.
Now, when i overwrote the contents of %hash_a, the contents in %hash_b where overwritten, too.
The whole stuff worked for more than one record only after I introduced the curly braces.

Comment on Re^4: How to build a hash?
Replies are listed 'Best First'.
Re^5: How to build a hash?
by davorg (Chancellor) on Apr 26, 2005 at 15:16 UTC

    There are two ways to take a reference to a hash.

    If you use the \%hash syntax then you are taking a reference to the _original_ hash. Any updates that you make through that reference will obviously update the original hash (as, actually, there is only ever one hash).

    If you use the { %hash } syntax then you are creating a new anonymous hash which is a _copy_ of your original hash and getting a reference to this new hash. Any updates you make through this reference will update the copy of the hash and not the original hash.

    I recommend reading "perldoc perlreftut" and "perldoc perlref" to clarify these concepts.


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

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2015-11-26 00:59 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (695 votes), past polls