in reply to Substring Sort

Well, since you said "efficient", I'll offer my favorite:

@origarray= @origarray[ do { my @by= map {(split(/\|/,$_,3))[2]} @origarray; sort {$by[$a] cmp $by[$b]} 0..$#origarray } ];
The above should be about as fast as you can get (though none of that matters unless you are sorting a huge number of items).

The "obvious" other two choices involve repeatedly extracting the substring to be compared (can be much slower but requires the least amount of memory), or using the Schwartzian Transform which does something similar to my method except it makes a ton of very small arrays w/o names instead of one array with a name (falls between the other two methods in speed but requires the most memory).

Update 2: Thanks to arhuman for reminding me of "my other favorite sorting scheme". His method is harder for me to compare. I suspect it may be faster and require only slightly more memory than mine above, at least for some cases. In any case, it is at least close.

I tend to use it when sorting on multiple fields, especially if they constitute most of the data. I use my method above to simultaneously sort multiple related lists (since none of the other methods can do that) -- though you have to save the list returned by sort to do that.

Updated to add missing ')'.

        - tye (but my friends call me "Tye")