Many wiser monks have had their say, so let me add my own $0.02.

If you're just storing data, use a Hash of Hashes (countles examples above).

If your data should be intelligent, use Objects. Consider and example similar to that in perltoot:

You run a business, you employ people (class 'Employee'). They all do different things, they all get paid different amounts and all work different hours. So, in procedural programming we'd have to know all this and branch around the place like crazy. With OO, it's all under the bonnet and we dont need to touch anything:

$roger = new Employee::Casual( rate => 14.00 ); $sally = new Employee::FullTime( salary => 50_000 ); $mark = new Employee::FullTime( wage => 12.00 ); $roger->add_hours( 8 ); # worked 8 hours $sally->add_hours( 8 ); # worked 8 hours $mark->add_hours( 8 ); # worked 8 hours # Now pay them $roger->write_check(); # 14 * 8 = $112.00 $sally->write_check(); # $0.00 - nothing due to a full timer until +fortnight is accounted for $mark->write_check(); # $0.00 - same here # add another 11 days # ... same as above, 11 times ... # then on day 13, it's a long day $roger->add_hours( 10 ); # worked 10 hours $sally->add_hours( 10 ); # worked 10 hours $mark->add_hours( 10 ); # worked 10 hours # So then they take day 14 off $roger->sick_leave( 8 ); # 8 hours $sally->sick_leave( 8 ); # 8 hours $mark->sick_leave( 8 ); # 8 hours # and get a work log: $roger->write_check(); # 11 days * 8 hours + 1 day * 10 hours = 98 hours @ $14.00 = $13 +72 # (no sick pay for casuals and we've already paid him for day 1) $sally->write_check(); # 14 days @ ($50000 / 365 days) = $1917 # (no overtime for sallary earners) $mark->write_check(); # 12 days * 8 hours + 1 day * 10 hours = 106 hours @ $12.00 = $1 +272 # get entitlements $roger->leave_entitlements(); # {sick_leave => 0, annual_leave => 0 +} - none for the casual $sally->leave_entitlements(); # {sick_leave => 56, annual_leave => + 8.6} $mark->leave_entitlements(); # {sick_leave => 56, annual_leave => +8.6}
As you can see, the objects are intelligent, so it doesn't matter that we tell all the objects ($roger, $sally and $mark) exactly the same thing, they all know, under the hood, what to do.

To learn how to do that, read perltoot. It's not only a good tutorial, it's an easy read and you'll come away having learned something about perl that you didn't know before. Plus, learning OO is very PerlMonk.

bless($me, $ISA[0]) for $i (sin($have));
"Get real! This is a discussion group, not a helpdesk. You post something, we discuss its implications. If the discussion happens to answer a question you've asked, that's incidental." -- nobull@mail.com in clpm

In reply to Re: When hashes aren't enough by BigLug
in thread When hashes aren't enough by Sprad

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!
  • 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, details, 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, summary, 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.