Is it just me or does this problem just scream OO? You have a bunch of data and a bunch of non-trivial work to do on that data. Why not create an object for each document's scoring? That way, you have a bunch of objects. You then have a really neat way of determing the list to display.
my $search_string = $cgi->param('search_string'); my @display_these = map { $_->[1] } # Strip off the ST sort { $a->[0] <=> $b->[0] } # Do the actual sort grep { $_->[0] > 0 } # Remove anything that scores a 0 map { [ $_->score($search_string), $_ ] } # Create the modified ST @document_objects;
The object would have a list of its words and how it scores. The object will probably be a hash (if you're lazy) or an array (if you're worried about space/speed). You'll have a hash of words that will key into hashrefs (cause they take less space when small) for all the ways something can score for that word. I dunno. :-)

Plus, you left out the part where this is really a 3-level structure, not a 2-level structure. You probably don't think of it that way, but you are de-referencing one level before you even get to the code posted above.

------
We are the carpenters and bricklayers of the Information Age.

Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.


In reply to Re: Hash of Arrays versus Two Hashes by dragonchild
in thread 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.