ww has asked for the wisdom of the Perl Monks concerning the following question:
This script, pure ASCII -- or so I think, is adapted from an example on sorting:
#!/usr/bin/perl use Modern::Perl; say "\n\n\t sort on multiple keys"; my @first = qw(John Joe John Jon Fred Rich); my @last = qw(Smith Smith Jones Jackson Jones Adler); my @index = sort { $last[$a] cmp $last[$b] or $first[$a] cmp $last[$b] } 0 .. $#first; for (@index) { say "$last[$_], $first[$_]"; } say "\n \t But, testing, single sort (cmp):"; my @sorted = sort { $a cmp $b } qw(John Joe John Jon Fred Rich); for (@sorted) { say "\t $_"; } =head execution sort on multiple keys Adler, Rich Jackson, Jon Jones, John Jones, Fred Smith, John Smith, Joe But, testing, single sort (cmp): Fred Joe John John Jon Rich ## sort puts "John" before "Joe" in the first instance but not in the +second: Why? =cut
Can someone point me to the document I failed to read or the section I failed to read carefully enough that explains the disparity in the output?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Variance in sort order (collation)
by tangent (Parson) on Feb 21, 2012 at 02:34 UTC | |
by ww (Archbishop) on Feb 21, 2012 at 02:43 UTC | |
|
Re: Variance in sort order (collation)
by Anonymous Monk on Feb 21, 2012 at 02:12 UTC | |
by ww (Archbishop) on Feb 21, 2012 at 02:16 UTC | |
by Anonymous Monk on Feb 21, 2012 at 02:35 UTC | |
by Anonymous Monk on Feb 21, 2012 at 05:35 UTC | |
by Anonymous Monk on Feb 21, 2012 at 08:41 UTC |