NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.
All the Perl that's Practical to Extract and Report
Stories, comments, journals, and other submissions on use Perl; are Copyright 1998-2006, their respective owners.
fwiw ... (Score:1)
# should probably be
if ( keys %order_by != @names ) {
If you didn't mind the performance hit of a tied hash, you could use my Tie::Hash::Sorted
You could combine your order sub and your sort routine in 1 by using lexicals and references. This way all you would need to do to change the sort order would be to change the array containing the list of keys - the rest would automagically happen. It would also allow you to add/delete/modify keys and values and always have the resul
Re:fwiw ... (Score:2)
Yup. That's a bug in my code, thanks :)
I can't use Tie::Hash::Sorted. I'm getting the hash from an external source. Thanks for the idea, though.
Re:fwiw ... (Score:1)
It does allow you to use an existing hash without damaging it in any way (it makes a copy).
Sounds like.... (Score:2)
File::Sort (Score:2)
Passing sort subs (Score:1)
osfameron
Anon subs work in sort as of 5.6.2 (Score:1)
As far as I understand perlfunc, sort accepts refs to anonymous subs. And I use such code all the time:
sort $sorter{$field}, @objs;Re:Anon subs work in sort as of 5.6.2 (Score:1)
Re:Anon subs work in sort as of 5.6.2 (Score:2)
Oops. You're quite right.
I tried it along time ago and found out it didn't work. I suppose I should have tried again :)