Gossamer Forum
Quote Reply
DBM
I have a DBM database which contains membership records with the 'key' of each record being the member's id (alpha, not numeric). I would like to print out the list in alphabetical order of member id, but try as I may, I can't get it to work. Anyone here familiar with DBM files?
Quote Reply
Re: DBM In reply to
Been a while since I used one, but something like:

Code:
dbmopen (%DB, "/path/to/dbfile", 0644) or die "Can't open: $!";
foreach sort (keys %DB) {
print "$_ => $DB{$_}\n";
}
dbmclose (%DB) or die "Can't close: $!";

Hope that helps,

Alex
Quote Reply
Re: DBM In reply to
Thanks Alex. It worked great. One last question on this. Some keys start with capital letters and some in small case. Is there a way to tell the sort to ignore case?
Quote Reply
Re: DBM In reply to
Sure. Replace the foreach line with:

foreach (sort { lc $a cmp lc $b } keys %DB) {

Might need to switch the $a and $b around, I never remember which way it should go for ascending or descending order.

Cheers,

Alex