Working from the first reply, which was a good start, I'm not sure this would qualify as "elegant", but it does what you want:
use strict; use warnings; use Data::Dumper; my @things_to_sort = ( { author => 'bart', title => 'skateboarding' }, { author => 'lisa', title => 'postmodernism' }, { author => 'marge', title => 'hairstyles' }, { author => 'lisa', title => 'THIS BOOK FIRST' }, { author => 'homer', title => 'donuts' }, { author => 'bart', title => 'coolness' } ); my ($first) = grep { $_->{title} eq 'THIS BOOK FIRST' } @things_to_sor +t; my @sorted = sort { $a->{title} cmp $b->{title} } grep { $_->{author} eq $first->{author} } @things_to_sort; push @sorted, sort { $a->{author} cmp $b->{author} or $a->{title} cmp $b->{title +} } grep { $_->{author} ne $first->{author} } @things_to_sort; print Dumper \@sorted;
I couldn't figure out a way to do it all in a single sort block -- especially when it comes to figuring out which author should be listed first. That just seemed to need an extra step at the outset. Maybe there's a way to use just one sort block after grepping for "THIS BOOK FIRST", but I haven't found it...

update: my first posting had a much more complicated block for the first sort -- which was a failed attempt to do everything in one sort -- but I simplified it to just the appropriate logic.


In reply to Re: Twisted sort requirements by graff
in thread Twisted sort requirements by forrest

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.