in reply to Module Proposal: Tie::SortHash
One I have used is DB_File. Just tie to a BTree and you can get keys back in sorted order. Custom sort functions and all. You can't sort on values, but I almost never would want to be able to do that, and if I did it would almost always be better to do it after the fact.
Reminds me though, a fun gotcha I shocked both the author of DB_File and the authors of Berkeley DB with. Consider the following sort function:
If you use this someone can store stuff in a locale sensitive order. Handy for those people in Europe with different alphabets.sub { use locale; $a cmp $b; }
What happens if someone changes the locale on their machine? And then starts using the database?
BOOM!
Instantly corrupted database! Completely silent!
So this is a handy sort sub to know about, but use with some caution. :-)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: RE (tilly) 1: Module Proposal: Tie::SortHash
by cwest (Friar) on Aug 19, 2000 at 00:13 UTC | |
by tilly (Archbishop) on Aug 19, 2000 at 00:18 UTC |