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

Re: [FWP] Sort challenge



>>>>> "RK" == Rick Klement <rklement@pacbell.net> writes:

  RK> Uri Guttman wrote:
  >> 
  >> print sort{lc$a cmp lc$b}
  >> map{/(.*)\|(.*)\|(.*)/;($2?"$2${$3&&\qq{, $3}}":$1).$/}<>
  >> 

  RK> This changes "pete||Peter" to "pete" when it should be "Peter" according
  RK> to the example given...

that seems true for some of the other variants we have seen:

print sort{lc$a cmp lc$b}map{/(.*)\|(.*)\|(.*)/;($2?$2.($3&&", $3"):$1).$/}<>

has the same bug as it outputs

est
Evans
Evans, Anne
Evans, Helen
Evans, Louise
pete
rwj
Sanchez

print sort{lc$a cmp lc$b}
map{/(.*)\|(.*)\|(.*)/;($2?join", ",$2,$3||():$3||$1).$/}<>

seems to work correctly. as does this:

print sort{lc$a cmp lc$b}
map{/(.*)\|(.*)\|(.*)/;($2&&$3&&"$2, $3"||$2||$3||$1).$/}<>

which is also the same size. this chops off one char:

print sort{lc$a cmp lc$b}
map{/(.*)\|(.*)\|(.*)/;($2&$3&&"$2, $3"||$2||$3||$1).$/}<>

and it still works. now let's get down and dirty. try this one out:

print sort{lc$a cmp lc$b}
map{chop;/\|(.*)\|/;($1&$'&&"$1, $'"||$1||$'||$`).$/}<>

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com

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