http://www.perlmonks.org?node_id=1012329


in reply to How to better represent a complex data structure.

Always bear in mind that Perl is a pragmatic language, built “out of necessity”   Lots of people (from “Larry Wall, himself” on forward) have faced the same problems that you did, and developed a pragmatic way to solve them.

In (this | your | their) case, the “magic pixie dust” is called references.   The apparent “complexity” of your situation in-fact arises from the fact that you need to insert “a complex data-structure” into one and only one place.   This requirement is very elegantly (and very completely ...) handled by the singular notion of “a reference,” which is:   “a single thing” (i.e. it can exist “in one place”) that can refer to (ommmm.....) anything-at-all.   (Furthermore, you can have any number of references to the selfsame thing ... so it can be in more than one place at the same time, if you so desire.)

The next key to this puzzle is ... that you can express this key notion without a bunch of extra steps.   In other words, without declaring a bunch of extra, otherwise-unnecessary variables.   Instead of “first” declaring @whatever and then later referring to \@whatever, you can simply describe what you really want, in one pragmatic step, and Perl will understand.

The Perl language is, after all, a human tool, that was originally conceived by someone who “had a job to ‘get done’,” and who devised the most-straightforward (to him... at the time ...) way, by which he could persuade a digital computer(!!) to do it.   (And hundreds if not thousands of other kindred souls, faced in their turn with the selfsame objective, have surely labored upon it since.)

Fact is... “Representing a complex data structure” is par for the course to every single one of us, from Larry Wall on down.   We’ve gotten very good at it.   ;-)

Replies are listed 'Best First'.
Re^2: How to better represent a complex data structure.
by eyepopslikeamosquito (Archbishop) on Jan 09, 2013 at 10:11 UTC

    “had a job to ‘get done’,”
    Awesome indeed. While quietly admiring your thoughtful placement of eleven pairs of “unnecessary quotes,” I was stunned by the inspired and original composition shown above: a pair of unnecessary single quotes embedded in a pair of unnecessary double quotes with a “chicago-manual-of-style” comma and some unnecessary typography thrown in for good measure! Well done.

Re^2: How to better represent a complex data structure.
by Amblikai (Scribe) on Jan 08, 2013 at 20:18 UTC

    Awesome reply! Thanks! I'll keep it in mind!