in reply to Twisted sort requirements
You are going to need a pre-pass of the data to find the author of the titled book. I've lower cased the titles for the sort so that "the book of ... " and "The book of..." will sort together, but that is easily removed. This assumes that your authors names and book titles don't contain null chars.
#! perl -slw 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 $firstTitle = 'THIS BOOK FIRST'; ## Find the author of the title my $firstAuthor; $_->{ title } eq $firstTitle and $firstAuthor = $_->{ author } for @things_to_sort; die "Title $firstTitle not found" unless $firstAuthor; my @sorted = map{ $_->[0] } sort { $a->[ 1 ] cmp $b->[ 1 ] } map { [ $_, sprintf "%s%s%s\0%s\0", $_->{ title } eq $firstTitle ? chr(0) : '', $_->{ author } eq $firstAuthor ? chr(0) : '', lc( $_->{ author } ), lc( $_->{ title } ) ] } @things_to_sort; printf "%-8s %-20s %-6s %-10s\n", %$_ for @sorted; __END__ c:\Perl\test>junk title THIS BOOK FIRST author lisa title postmodernism author lisa title coolness author bart title skateboarding author bart title donuts author homer title hairstyles author marge
|
|---|