in reply to Golf: Arbitrary Alphabetical Sorting

This solution uses the same approach as merlyn's, translating the words so they can be compared directly. It assumes that the words will not contain the null character.

96 characters.

sub o { @k{@$A}=map chr,1..@{$A=$_[0]}; map{s/.*\0//s;$_}sort map{($x=$_)=~s/./$k{$&}/gs;"$x\0$_"}@{+pop} }
BTW, although %k is not lexicalized to the sub, I don't think it matters, since any leftover contents which are not overwritten won't be used. (Also assume that no other characters are present in the words.)

Update: I added /s to both substitutions, to avoid problems with \n. Thanks tilly!

Replies are listed 'Best First'.
Re (tilly) 1: Golf: Arbitrary Alphabetical Sorting
by tilly (Archbishop) on May 09, 2001 at 21:36 UTC
    Note that in addition to not allowing \0 as a character you don't allow \n.