I have a search engine which takes each 'find' or search result from a database, calculates the percentage match, and takes all of the 'find' info and puts it all together into a string, which it adds to an array (each array item is a search result).

Example array:

@records = (".66+5638+copper globe",
            "1.00+1396+the blocks",
            ".33+4055+hunt draw");


As you might have guessed, this database has to do with geographic locations. The strings above are delimited using plus signs. The first item in each string is a decimal resulting from a match calculation ($words_found\$words_searched), which will be multiplied later in the script by 100, and a '%' character will be appended to this string when the match percentage will actually be displayed.

My problem is sorting the percentages. I obviously want the 100% match search results to appear before the 66%'s, 33%'s, or whatever. In older versions of this script, the 100% would come first, the 33% second, and 66% were last, for example.

I tried:

$a = 0; $b = 1;
@records = sort {$b <=> $a} @records;


but since they are strings with a bunch of other stuff in it, the script complained.

I don't want to rip the individual delimited strings apart to sort the array; its already a memory hogging script as it is.

Anyone have any ideas?

Thanks

In reply to Numerically sorting array items containing delimited strings by ti-source

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.