Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Inserting an array in an array of hashes

by sundialsvc4 (Monsignor)
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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (14)
As of 2014-08-01 16:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Who would be the most fun to work for?















    Results (32 votes), past polls