Hello, I recently started on a project to improve a bit of my code and thought this would be an easy point, but am not finding much information to address what I'm trying to do. I have a MySQL database that I populate with data points from text files. Today I do most of the gleaning of that information from a hodge-podge of PHP code. I was trying to move the searching and matching to perl instead, figuring I could work in a lot of improvements at the same time. For instance, I have a table in the database holding Artists. In my perl script, I connect to MySQL, get the artists out and put them into a hash. Next I open the relevant text file, grab every line and place that into an array. I then want to check each item in the array and see if it matches an item from the hash. This works wonderfully like this:
for (my $i=0;$i<=$#lines;$i++){ if(exists $artists{$lines[$i]})
But I was hoping to add some ranking of the match to present the user with the most likely artist for that text file. I would eventually write the matches back into a MySQL table to present later. I'm thinking an exact full line match = 256, a case insensitive full line match = 128, a partial word match = 64, etc. Then I could add up all of the matches for one artist and rank them for the user. I'm surprised to not find a method to do this without re-inventing the wheel. Am I going about this wrong? Any wisdom to point me in a different direction? Thanks!

In reply to Hash Search Ranking by hoyt

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.