I'm reviewing some search-engine-like code which scores documents according to two different criteria.

One is "number of times word appears", and the other is "contains n of the words searched for".

It's a crude but effective way of scoring documents.

If the search term is "apple banana cherry" a document may score 10 for its apple-content, 5 for its banana-content, 1 for its cherry-content, a score of 16, but then get a "bonus" of fifty points for containing all three words, putting it ahead of another document with 20 for cherry, 20 for banana but zero for apple.

When I wrote the code a year ago I never would have thought of using multidimensional structures, but having hung around the Monks for a year, it occurs to me that I can do it this way:

$total_word_score{$this_document} = 16; $number_of_matches{$this_document} = 3;
keeping two hashes, or I can do it this way:
$various_scores{$this_document} = [16,3];

are there any arguments -- stylistic, maintenance, extendability -- about doing it one way rather than the other?
--

“Every bit of code is either naturally related to the problem at hand, or else it's an accidental side effect of the fact that you happened to solve the problem using a digital computer.”
M-J D

In reply to Hash of Arrays versus Two Hashes by Cody Pendant

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.