No Schwartzian transorm, but this seems to do it:
#!/usr/bin/perl -w use strict; # Build a utility array for sorting by size our @sizes=qw(s m l xl); our %sizeval; { my $i = 0; $sizeval{$_}=$i++ foreach @sizes; } # Build the array to test my @arr; while (<DATA>) { chomp; push(@arr,{ sortval => $_ }); } # Now sort the results and print them foreach (sort bysizecolor @arr) { print $_->{sortval},"\n"; } # Sort hashrefs by size and color sub bysizecolor { my ($a_size,$a_color) = getsizecolor($a->{sortval}) or warn("Couldn't parse '$a'"),return 0; my ($b_size,$b_color) = getsizecolor($b->{sortval}) or warn("Couldn't parse '$b'"), return 0; return bysize($a_size, $b_size) || bycolor($a_color, $b_color); } # Compare two sizes sub bysize { my($a,$b)=@_; $sizeval{lc $a} <=> $sizeval{lc $b}; } # Compare two colors sub bycolor { my($a,$b)=@_; lc $a cmp lc $b; } # Extract the size and color from a string sub getsizecolor { return ($_[0] =~ m!\w+:\s(\w+),\s\w+:\s(\w+)!); } __DATA__ size: L, color: White size: M, color: Orange size: M, color: White size: M, color: White size: S, color: Orange size: S, color: White size: Xl, color: Orange size: Xl, color: White size: Xl, color: White

In reply to Re: complicated sorting issue by sgifford
in thread complicated sorting issue by geektron

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.