[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] Sort challenge



Lou Hevly wrote:
> 
> Greetings all:
> 
> Given the following data:
> 
> __DATA__
> ae|Evans|Anne
> le|Evans|Louise
> he|Evans|Helen
> je|Evans|
> pete||Peter
> xs|Sanchez|
> rwj||
> est||
> 
> 1) If there's a last name, the program should sort first by that and then by the firstname (if there is one);
> 2) If no last name, then sort by first name;
> 3) If neither last nor first name, then sort by username
> 
> So the desired result is:
> 
> est
> Evans
> Evans, Anne
> Evans, Helen
> Evans, Louise
> Peter
> rwj
> Sanchez
> 
> All the best (Adéu-siau),
> Lou Hevly
> lou@visca.com
> http://www.visca.com
> 

This seems way too long...

#!/usr/bin/perl
print sort{lc$a cmp lc$b}map/\|(.+)\|(.+)/&&"$1, $2\n"||
/.*\|(.+)\||.*\|\|(.+)|(.+)\|\|/&&"$1$2$3\n",<DATA>

-- 
Rick Klement

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe