EDIT: Oops, had to update code for people with identical scores, and people who weren't on previous listing.
use strict; use warnings; my (%lrank, $c, $s, $name, $score, $lrank, $lscore); my @lrank = ('RUBYKAT','SAPER','PETDANCE','AMBS','BARBIE'); my @nrank = ( ['PETDANCE',12.4], ['SAPER',15.78], ['AMBS',15.5], ['RUBYKAT',15.97], ['BARBIE',16.06], ['NEWBIE',12.4], ); $lrank{$_} = $c++ for @lrank; $s = '%' . (length($#nrank+1)+1) . 's'; @nrank = sort {@$b[1] <=> @$a[1] || @$a[0] cmp @$b[0]} @nrank; $c = 0; $lscore = 0; for (@nrank) { ($name, $score) = @$_; if (exists $lrank{$name}) { $lrank = $lrank{$name}; print $lrank > $c ? '^' : $lrank < $c ? 'v' : ' '; } else { print ' '; } print sprintf $s, $lscore == $score ? '' : $c; print ": $name\n"; $lscore = $score; $c++; }
Note that people of the same score are currently sorted alphabetically. Could be you'd want them sorted according to first come, first served, in which case a more complicated algorithm would be necessary.

In reply to Re: looking for a module to handle 'highscore' lists by TedPride
in thread looking for a module to handle 'highscore' lists by domm

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.