mikasue has asked for the wisdom of the Perl Monks concerning the following question:

I am using the sort method to sort names I retrieve from a database. Initially it works but if I try to access this same method a second time without closing out of my program, I get the following error
Use of uninitialized value in string comparison (cmp) at bppcsvver.pl +line 539. Tk::Error: Can't set -options to `ARRAY(0x1d1d0dc)' for Tk::Optionmenu +=HASH(0x3a c6244): No -label at C:/Perl/site/lib/Tk/Widget.pm line 256 at C:/Perl/site/lib/Tk/Derived.pm line 294 at C:/Perl/site/lib/Tk/Derived.pm line 306 Tk callback for .toplevel7 Tk callback for .toplevel7.frame Tk::Derived::configure at C:/Perl/site/lib/Tk/Derived.pm line 306 Tk::Widget::new at C:/Perl/site/lib/Tk/Widget.pm line 205 Tk::Widget::__ANON__ at C:/Perl/site/lib/Tk/Widget.pm line 256 BPP::Accounts::EditViewAccountsScreen at bppcsvver.pl line 550 BPP::BPPDEFAULTS::__ANON__ at BPP/BPPDEFAULTS.pm line 25
Here is my code:
my $a_user= $activeuserName; my %AccountHash; my @activeUserAccts=(); my $activeUserCount=0; @activeUserAccts = sort{$a->{acct_name} cmp $b->{acct_name}} BPP +::ACCOUNT->getActiveUser($activeuser); $activeUserCount = @activeUserAccts; my $active_user_acct = $acct_frame->Optionmenu(-options=>[map {[$_ +->{acct_name}=>$_->{acct_id}]} @activeUserAccts], -command=>sub {},-v +ariable=>\$activeUserAccts[0], -width=>25 )->grid(-row=>3, -column=>1 +,-sticky=>'nw'); $active_user_acct->addOptions(" ");
I dont' see what's uninitialized in my sort statement. Please help!

Replies are listed 'Best First'.
Re: Uninitialized Value in Sort
by runrig (Abbot) on Sep 27, 2006 at 19:19 UTC
    I dont' see what's uninitialized in my sort statement.

    Neither do I (though I would assume one or more of the values in the list you're sorting do not have an acct_name key). Print out what you're sorting before you sort it:

    use Data::Dumper; my @accounts = BPP::ACCOUNT->getActiveUser($activeuser); print Dumper(\@accounts);
      ++runrig The second time through it's not printing all fields. Here is my output:
      here are the active user accounts$VAR1 = bless( { 'acct_name' => 'CLC', 'acct_type' => '15', 'acct_balance' => '1.00', 'acct_interestrate' => '0', 'acct_status' => '1', 'acct_zip' => '', 'acct_num' => '', 'acct_primaryname' => 'Golly Gee', 'acct_state' => '', 'acct_securitycode' => '', 'acct_minbalance' => '', 'acct_city' => '', 'acct_id' => '9', 'acct_phone' => '555-987-5666', 'acct_limit' => '0', 'acct_expiration' => '1/1/2007', 'acct_address' => '', 'acct_website' => '', 'acct_email' => '', 'acct_notes' => '', 'user_id' => '101', 'acct_fax' => '' }, 'BPP::ACCOUNT' ); $VAR2 = bless( { 'acct_name' => 'SouthWest', 'acct_type' => '46', 'acct_balance' => '400.00', 'acct_interestrate' => '6%', 'acct_status' => '1', 'acct_zip' => '', 'acct_num' => '20', 'acct_primaryname' => 'TSC', 'acct_state' => 'IL', 'acct_securitycode' => '', 'acct_minbalance' => '100.00', 'acct_city' => 'Erewhon', 'acct_id' => '5', 'acct_phone' => '555-382-2838', 'acct_limit' => '', 'acct_expiration' => '08/28/2007', 'acct_address' => '', 'acct_website' => 'www.southwest.com', 'acct_email' => 'southwest@bogus.com', 'acct_notes' => '', 'user_id' => '101', 'acct_fax' => '' }, 'BPP::ACCOUNT' ); Use of uninitialized value in string comparison (cmp) at bppcsvver.pl +line 540. here are the active user accounts$VAR1 = bless( { 'acct_type' => '15', 'acct_securityCode' => '12341', 'acct_status' => '1', 'acct_interestRate' => undef, 'acct_minBalance' => undef, 'acct_id' => '9', 'user_id' => '101' }, 'BPP::ACCOUNT' ); $VAR2 = bless( { 'acct_name' => 'SouthWest', 'acct_type' => '46', 'acct_balance' => '400.00', 'acct_interestrate' => '6%', 'acct_status' => '1', 'acct_zip' => '', 'acct_num' => '20', 'acct_primaryname' => 'TSC', 'acct_state' => 'IL', 'acct_securitycode' => '', 'acct_minbalance' => '100.00', 'acct_city' => 'Erewhon', 'acct_id' => '5', 'acct_phone' => '555-382-2838', 'acct_limit' => '', 'acct_expiration' => '08/28/2007', 'acct_address' => '', 'acct_website' => 'www.southwest.com', 'acct_email' => 'southwest@bogus.com', 'acct_notes' => '', 'user_id' => '101', 'acct_fax' => '' }, 'BPP::ACCOUNT' ); Tk::Error: Can't set -options to `ARRAY(0x39bd2cc)' for Tk::Optionmenu +=HASH(0x39 ed02c): No -label at C:/Perl/site/lib/Tk/Widget.pm line 256 at C:/Perl/site/lib/Tk/Derived.pm line 294 at C:/Perl/site/lib/Tk/Derived.pm line 306 Tk callback for .toplevel2 Tk callback for .toplevel2.frame Tk::Derived::configure at C:/Perl/site/lib/Tk/Derived.pm line 306 Tk::Widget::new at C:/Perl/site/lib/Tk/Widget.pm line 205 Tk::Widget::__ANON__ at C:/Perl/site/lib/Tk/Widget.pm line 256 BPP::Accounts::EditViewAccountsScreen at bppcsvver.pl line 555 BPP::BPPDEFAULTS::__ANON__ at BPP/BPPDEFAULTS.pm line 25 (menu invoke) C:\Documents and Settings\Tamika Cashaw\My Documents\My Programs\BPP>
      I wonder why it's omitting those fields. Thanks for helping me investigate.

      Edited to remove possible personal data by GrandFather

        Completely off-topic, but you *NEVER* ever should print out sensitive information like people's real names, their phone numbers, emails, etc. on public forums like this one!!! If you need to publish your data, always substitute such info with bogus information.

        BR
Re: Uninitialized Value in Sort
by Joost (Canon) on Sep 27, 2006 at 19:14 UTC
Re: Uninitialized Value in Sort
by davidrw (Prior) on Sep 27, 2006 at 23:21 UTC
    The "uninitialized value" is because ->{acct_name} isn't defined, which you can see in your reply of the Dumper output ... so the question is why that first array element from getActiveUser() doesn't have all the data it should ... Maybe a reference issue where somewhere else in the program, between calls to this sort code, you actually modify $activeUserAccts[0] somewhere?
    ... Ah -- yes. Note that you have -variable=>\$activeUserAccts[0] in the $acct_frame->Optionmenu() call ... that's what's going to be destorying/overwriting in some way the first BPP::ACCOUNT hashref.


    The other part, Can't set -options to `ARRAY(0x1d1d0dc)' ... might be caused by the first issue. do confirm, do this (the above error might be causing a malformed data structued; note thet Tk::Optionmenu wants something like -options => [[jan=>1], [feb=>2], [mar=>3], [apr=>4]]):
    my $opts = [map {[$_->{acct_name}=>$_->{acct_id}]} @activeUserAccts]; print Dumper $opts; my $active_user_acct = $acct_frame->Optionmenu(-options=>$opts, -comma +nd=>sub {},-variable=>\$activeUserAccts[0], -width=>25 )->grid(-row=> +3, -column=>1,-sticky=>'nw');