Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re^4: Golf: Arbitrary Alphabetical Sorting

by tadman (Prior)
on May 10, 2001 at 03:04 UTC ( #79284=note: print w/ replies, xml ) Need Help??

in reply to Re (tilly) 3: Golf: Arbitrary Alphabetical Sorting
in thread Golf: Arbitrary Alphabetical Sorting

TMTOWTDI, as they say, and this one appears to be 70 characters:

sub o { ($c,*w,$")=@_;sub t{eval"y/@$c/\0-\377/";$_}sort{t($_=$a)cmp t$_=$b}@w }

Comment on Re^4: Golf: Arbitrary Alphabetical Sorting
Download Code
Replies are listed 'Best First'.
Re: Re^4: Golf: Arbitrary Alphabetical Sorting
by chipmunk (Parson) on May 10, 2001 at 05:18 UTC
    Unfortunately, that fails if @$c includes a slash. Fixing this bumps it up to 74 characters:
    sub o { ($c,*w,$")=@_;sub t{eval"y/\Q@$c\E/\0-\377/";$_}sort{t($_=$a)cmp t +$_=$b}@w }
      I find this turn of events absolutely astounding, and I only have one thing to add.

      It may not display well, but the two escape sequences can be replaced by the actual characters. This brings it back down to 70. Here is the paste from my system, this may not work on yours:

      sub o{ ($c,*w,$")=@_;sub t{eval"y/\Q@$c\E/-/";$_}sort{t($_=$a)cmp t$_=$b}@w }

      It definitely won't work on yours. It seems the \0 was trimmed from the output. To get what you need go back to chipmunk's post, download his code to a file, then run this:

      perl -pi.bak -e 's/\\(\d+)/chr(oct($1))/e' filename
      (Use " instead of ' on Windows.) The resulting file will have the key subroutine reduced to 70 characters, and will still run.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://79284]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2015-11-26 00:49 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (695 votes), past polls