Just another Perl shrine | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
> The Perl code works but compared to the Python version it looks a little bit awkward.
The question is if you want it fast or pretty. Without extra modules, this doesn't look particular awkward to me.
of course it's far more efficient to store the index in a hash, which in turn needs to be precalculated. Others have shown you external "sort_by" implementations using so-called "key-functions" like in Python ( That's when you can avoid to repeat code for $a and $b). But I'm not sure if these key-functions - in Python or CPAN - actually cache the results for performance optimization in a hash. (This might be too clever if a key function is supposed to vary results) Which brings us back to the question: fast or pretty?
Cheers Rolf In reply to Re: Sort list by position of items in another list
by LanX
|
|