Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Where are you having trouble? With many sorts of problem I find breaking things up into smaller chunks helps a lot. I'll bet you already use that technique for managing code using subroutines and modules for example. So how can you do that for data? One way that can help is to create temporary variables that provide access to the current part of a structure that you are interested in. Consider:

sub itemPrice { my ($self, $itemName) = @_; my $item = $self->{invent}{current}{items}{$itemName}; return $item->{price}; }

Ok, no great advantage in such a trivial case, but if you needed to access $item multiple times the virtue is obvious. Very often such a technique is valuable in a loop where you are iterating over items but accessing the item is somewhat indirect.

In most cases once you have a grasp of the general principals for managing references the rest of the details are very specific to your actual data structure and application. Some times a recursive technique does the magic, other times using a temporary reference as suggested above is the trick. Some times wrapping the access up in a sub may be the best medicine.

True laziness is hard work

In reply to Re: Nested Data Structures for Dummies? by GrandFather
in thread Nested Data Structures for Dummies? by jedikaiti

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others avoiding work at the Monastery: (5)
    As of 2018-03-21 09:46 GMT
    Find Nodes?
      Voting Booth?
      When I think of a mole I think of:

      Results (265 votes). Check out past polls.