i have an array of hashrefs to sort by one of the values. sounds simple, but i need to do a 2-level sort on the contents of a string ...

it sounds like a job for the Schwartzian Transform, but i'm at a loss on how to build the temp array/hash then reconstruct the original.

the values i need to sort on look like this:

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
I need to sort the array of hashrefs by color, then by size, but since (obviously) S should come before M ... an alpha or ascii sort won't work. i *think* i need a mapping hash also.

i have the regex to get the values out of the string ... but now, how to apply that into a Schwartzian and reconstruct?

my $string = $element->{description}; $string =~ m!\w+:\s(\w+),\s\w+:\s(\w+)!;
where $2 would be the first sort criteria, $1 the second ... so that i end up with ordering like:
size: S, color: Orange size: S, color: White size: M, color: Orange size: M, color: White size: M, color: White size: L, color: White size: Xl, color: Orange size: Xl, color: White

In reply to 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.