Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Hmm. I just realized there's another interpretation of the question that might be
more valid than my other solution.
Suppose the question means: given elements of @list2 which begin with the letters of @list, rearrange them so that the beginning letters are sorted in that order. Thus, the length of @list2 in no way correlates with the length of @list, and this was merely a concidence in the sample set. To that, I'll have to add two arbitrary decisions: if the word doesn't begin with one of the letters, put it first, and within a given initial letter, sort alphabetically. The code for that would look like this: There. One of them there, Schwartzian thingies. And yes, I see other similar solutions in this thread, but I bet those repeated index() calls inside the sort comparator are gonna make it doggy slow for dozens of elements. By caching the reverse map, as well as the sort position, we save mondo time. -- Randal L. Schwartz, Perl hacker In reply to Re: sorting based on a list
by merlyn
|
|