Here's my go at the flagValue sub.

It uses a lookup but also inverts the logic so that an 'R' will return a high number (yours returned 1). Any $flags string that contains an 'R' will be higher than any combination without an 'R' and so on for the others.

You would need to reflect the change in your sort routine.

I would consider processing these values beforehand maybe adding them to @tagIndexes.

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my %flagvalues = ( R => 2**6, T => 2**5, B => 2**4, I => 2**3, F => 2**2, L => 1, ); my $flags = 'RRTBLXUC'; print flagValue($flags); sub flagValue{ $flags = shift; my $weight; my %unique_flags = map { $_ => undef } split //, $flags; for my $flag (keys %unique_flags){ $weight += exists $flagvalues{$flag} ? $flagvalues{$flag} : 0; # print "$flag -> $weight\n"; } return $weight; }
Update:

It also relies on any flag appearing only once.

Update 2:

Updated to only weigh a flag once.


In reply to Re: Pimp my code - Schwartzian transform maybe? by wfsp
in thread Pimp my code - Schwartzian transform maybe? by GrandFather

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.