in reply to Twisted sort requirements
With a little work before hand sort is the tool to use:
use warnings; use strict; 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 @authors = grep {$_->{title} eq 'THIS BOOK FIRST'} @things_to_sort; print "$_->{author}: $_->{title}\n" for sort TwistedSort @things_to_s +ort; sub TwistedSort { if ($a->{author} eq $b->{author}) {# Same author, just check title return -1 if $a->{title} eq $authors[0]->{title}; return 1 if $b->{title} eq $authors[0]->{title}; return $a->{title} cmp $b->{title}; } return -1 if $a->{author} eq $authors[0]->{author}; return 1 if $b->{author} eq $authors[0]->{author}; return $a->{author} cmp $b->{author}; }
Prints:
lisa: THIS BOOK FIRST lisa: postmodernism bart: coolness bart: skateboarding homer: donuts marge: hairstyles
|
|---|