Yep, works. Thanks for showing an alternate way without using the tr/// trick. Now to 
go through it character by character to try to understand it...

Thanks, again, Bob.

-Kevin

>>> Bob Showalter <[EMAIL PROTECTED]> 08/14/03 10:39AM >>>
KEVIN ZEMBOWER wrote:
> Here's a sure sign of someone with too much time on his hands:
> 
> 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:
> RWQOJMVAHBSGZXNTCIEKUPDYFL
> 
> So, for instance, if STDIN is a cat of the file of candidates' names:
> Bock, Audie E. Bustamante, Cruz M.
> Feinstein, Dan
> Flynt, Larry
> Kennedy, Edward Thomas
> Nave, Paul James
> Novello, Donald A.
> 
> STDOUT would be the sorted list:
> Bock, Audie E. # Because O comes before U
> Bustamante, Cruz M.
> Novello, Donald A. # Because O comes before A
> Nave, Paul James
> Kennedy, Edward Thomas
> Feinstein, Dan # Because E comes before L
> Flynt, Larry
> 
> (if I did it correctly).
> 
> So, what's the most perl-ish way to write such a beast? Bonus points
> for a one-liner. 

Here's my stab at a semi-obfuscated version:

perl -e '$"=qq{Davis, Gray
M.},split//,q/RWQOJMVAHBSGZXNTCIEKUPDYFL/;&{sub{map($_{+lc}=++$_{$_},@_),pop
while @_}};s/.*\///,print for reverse sort map "@{[map
sprintf(q[%2d],$_),map$_{$_},split//,$_]}\/$_",<>'

Remove any line breaks from that; it's all one long line. Supply the input
to stdin.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED] 
For additional commands, e-mail: [EMAIL PROTECTED] 



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to