The best way is definitely to use a hash of hashes, as shown by toolic. Nothing complicated in that case really try to use his proposal.

Now, if you don't feel comfortable with nested data structures, you have the right to use two hashes, one for summing the values, and another one for the mapping of USERIDs to names.

This is maybe slightly less efficient (at least in terms of coding and possibly storing performances), but do we care, provided that it does what you want? No, we usually don't.

Perl has a tradition of being nice with people writing "baby Perl", i.e. using only a relatively small subset of the language. As chromatic says in the Modern Perl book, "this baby Perl is a term of endearment, because everyone begins as a novice." The Programming Perl (or "Camel book") reference book is on the same line. And this is also my personal experience: I am rather happy that I have no longer have the source of my first Perl programs, I would probably find them very badly written. Yet, they did what I wanted, and they did it quite efficiently.


In reply to Re: Best way to store/sum multiple-field records? by Laurent_R
in thread Best way to store/sum multiple-field records? by bobdabuilda

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.