>>>>> "Kevin" == Kevin Zembower <[EMAIL PROTECTED]> writes:
Kevin> Here's a sure sign of someone with too much time on his hands:
Kevin> I was curious how to implement an algorithm in perl to sort the candidates in
California's recall ballot. According to the news, here's the sort order:
Kevin> RWQOJMVAHBSGZXNTCIEKUPDYFL
Kevin> So, for instance, if STDIN is a cat of the file of candidates' names:
Kevin> Bock, Audie E.
Kevin> Bustamante, Cruz M.
Kevin> Feinstein, Dan
Kevin> Flynt, Larry
Kevin> Kennedy, Edward Thomas
Kevin> Nave, Paul James
Kevin> Novello, Donald A.
Kevin> STDOUT would be the sorted list:
Kevin> Bock, Audie E. # Because O comes before U
Kevin> Bustamante, Cruz M.
Kevin> Novello, Donald A. # Because O comes before A
Kevin> Nave, Paul James
Kevin> Kennedy, Edward Thomas
Kevin> Feinstein, Dan # Because E comes before L
Kevin> Flynt, Larry
Kevin> (if I did it correctly).
Kevin> So, what's the most perl-ish way to write such a beast? Bonus points for a
one-liner.
This seems to do the right thing, although it's not yet one line. :)
print
map $_->[0],
sort { $a->[1] cmp $b->[1] }
map {
(my $k = $_) =~
tr/RWQOJMVAHBSGZXNTCIEKUPDYFLrwqojmvahbsgzxntciekupdyfl/A-ZA-Z/;
[$_, $k];
} <DATA>;
__END__
Bock, Audie E.
Bustamante, Cruz M.
Feinstein, Dan
Flynt, Larry
Kennedy, Edward Thomas
Nave, Paul James
Novello, Donald A.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[EMAIL PROTECTED]> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]