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...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;
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |