This question reminded me my old note I kept for case. It doesn't cover the actual topic but can be (or cannot be) considered as some hint.
#!/usr/bin/env perl use strict; use warnings; use List::Util qw(max); # Lower weight means higher precedence my %weight_map = ( alligator => 100, bear => 90, cat => 80, jellyfish => 10, zebra => 1, ); my $weight_lowest = max(values %weight_map) + 1; my @z0 = qw/ bear wolf jellyfish zebra dog fox cat /; my @z1 = sort { $a cmp $b } @z0; my @z2 = sort { ( $weight_map{$a} // $weight_lowest ) <=> ( $weight_map{$b} // $weight_lowest ) or $a cmp $b; } @z0; print <<RESULT; unsorted : [@z0] sorted : [@z1] weighted : [@z2] RESULT
And the execution results to:
unsorted : [bear wolf jellyfish zebra dog fox cat] sorted : [bear cat dog fox jellyfish wolf zebra] weighted : [zebra jellyfish cat bear dog fox wolf]

In reply to Re: Randomly choosing from a set of alternatives with varying popularity by siberia-man
in thread Randomly choosing from a set of alternatives with varying popularity by ibm1620

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.