Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: Inserting an array in an array of hashes

by sundialsvc4 (Abbot)
on Oct 18, 2012 at 20:04 UTC ( #999813=note: print w/replies, xml ) Need Help??

in reply to Inserting an array in an array of hashes

Also bear in mind that the way in which Perl is actually doing this, explicitly or implicitly, is through the magic of references.   The value associated with a particular hash-key, like a particular element in an array, is always “a single scalar,” but ... a reference is “a single scalar,” no matter what it refers to.   That is the secret to creating arbitrary data-structures in Perl.   The memory-manager allows an arbitrary number of references to exist to the same piece of data and maintains a reference-count for each piece, automatically disposing of no-longer-referenced pieces.

So, Perl’s technically-correct view of your title line would be:   “inserting a reference to an array, into one of the hashes which are referenced by:   an array, whose elements happen to entirely consist of:   references to hashes.”

Self-evident:   hashref is slang for “reference to a hash;” arrayref is slang for “reference to an array.”

Perl is a very forgiving language that encourages “say what I mean,” allowing you to say the same thing in several different ways ... but it is important to bear in mind that this is how all those ways of saying it wind up.   References are one of the “cornerstone ideas” of this language.

  • Comment on Re: Inserting an array in an array of hashes

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (6)
As of 2018-11-21 03:29 GMT
Find Nodes?
    Voting Booth?
    My code is most likely broken because:

    Results (236 votes). Check out past polls.