Sorting DBM Hash Greetings: I've run into what appears to be a conflict in sorting a DBM Hash. The DBM is opened and closed through tie and untie to store selections from Perl Tk medical questionnaire which uses checkboxes, radio buttons and lists, and contains over 200 items. I'm attempting to verify that all user selections are accurately stored in the DB. The first sort routine prints out keys and value. However it fails to include some keys and values such as variable ckb_100 or ckb_104 (or their values). When I use Randal Schwartz's sort from Learning Perl, it (by design) lists keys sorted by value order (without listing values), but includes all keys in the DB including those keys dropped in the first sort. I have reviewed the PerlTk program a number of times and can't find an error (realize this doesn't mean there isn't one). But why would Randal's sort contain a key that is not included in the other sort? Randal's sort indicates all user selections are included in DB; other sort does not.
Here's the first sort code on the DBM Hash; it fails to list all keys and their values. #!/usr/local/bin/perl use warnings; use SDBM_File; #load database module which is a clone of DBM provided by ACTIVE STATE $db = "c:/temp/userstats.db"; #where data is kept between runs dbmopen(%DATA, $db, 0666 ) or die( "Can't open: $!" ); foreach my $key ( sort { $a <=> $b } keys %DATA ) { print "$key => $DATA{$key}\n"; } Here's Randal Schwartz', Learning Perl,sort; it lists all keys. #!/usr/local/bin/perl use warnings; use SDBM_File; #load database module which is a clone of DBM provided by ACTIVE STATE $db = "c:/temp/userstats.db"; #where data is kept between runs dbmopen(%DATA, $db, 0666 ) or die( "Can't open: $!" ); my @choices = sort by_score_and_name keys %DATA; sub by_score_and_name { $DATA{$b} <=> $DATA{$a} #by descending numeric score or $a cmp $b #ASCIIbetically by name } print "@choices, \n"; dbmclose(%DATA); Here's a typical PerlTk GUI: #Post Traumatic Stress Disorder $ckb_100 = $frme_name1a -> Checkbutton(-text=>"post traumatic stress disorder", -variable=>\$post2, -command =>\&variable_100); $ckb_100-> deselect(); $ckb_100-> form(-left=>460, -top=>585); An anonymous sub routine is used to hold sub routines for all the question variables. Here's a standard sub for checkbox. sub variable_100 { my $x = ${$ckb_100 ->cget(-variable)}; if ($x == 1) { $DATA{ckb_100} = "1"; } else { } } Thanks for any insights. John Burns