Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

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

Title:
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!
  • 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
  • Outside of code tags, you may need to use entities for some characters:
            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?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others chanting in the Monastery: (8)
    As of 2014-07-12 12:59 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      When choosing user names for websites, I prefer to use:








      Results (240 votes), past polls