Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( [id://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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (3)
As of 2024-04-20 01:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found