Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

TK MListbox random issue

by lightspd (Initiate)
on Feb 11, 2013 at 17:55 UTC ( #1018203=perlquestion: print w/ replies, xml ) Need Help??
lightspd has asked for the wisdom of the Perl Monks concerning the following question:

Hello all, I've got a random issue, that I'm having a hell of a time tracking down and am hoping someone can help or give a suggestion. The MListbox seems to work fine till it will randomly stop displaying results and I get the following error. Can't use string ("") as a subroutine ref while "strict refs" in use at /usr/lib/perl5/vendor_perl/5.8.8/Tk/ line 700. I've checked my returned results and nothing changes or is strange. Here is the section of code that is having issues. UPDATE: Upon further looking, a variable in the becomes undef. Which I'm not sure how that's happening. Maybe someone who understands it more than I will know? The second section of code is taken from $code becomes undef.

my $searchRes = $top->DialogBox(-title => 'Search Results', -buttons => ['OK', 'Cancel'],) +; my @dispRes = qw(ID FirstName LastName); my $ml = $searchRes->Scrolled( qw/MListbox -selectmode single -scrollbars oe -font sm +all / )->pack(-expand => 1, -fill => 'both'); foreach my $colHdrs (@dispRes){ $ml->columnInsert('end',-text=>$colHdrs); } foreach (@dispRes){ push @row, $hash{$_}; } $ml->insert('end', \@row); $ml->see('end'); <-- Error get's thrown here print Dumper($ml->getRow('end')); $ml->update; my $answer = $searchRes->Show();
sub _selectionUpdate { my ($w, $code, $l, @args) = @_; ; if (@args) { foreach (@{$w->{'_columns'}}) { &$code($_->Subwidget("listbox"), @args); } } else { &$code($w->{'_columns'}->[0]->Subwidget("listbox")); } }

Comment on TK MListbox random issue
Select or Download Code
Re: TK MListbox random issue
by thundergnat (Deacon) on Feb 11, 2013 at 19:49 UTC

    Hmmmm.... perl 5.8.8? Sigh. Ok, I'm going to take a really wild stab. My suspicion is that your @dispRes array is empty when you are building your column headers. Change the line:

    foreach my $colHdrs (@dispRes){ $ml->columnInsert('end',-text=>$colHdrs); }


    foreach my $colHdrs (@dispRes || 'oops'){ $ml->columnInsert('end',-text=>$colHdrs); }

    and see if that helps pinpoint the trouble.

      Changed, but I'm not sure how it would become empty randomly. As far as 5.8.8 is concerned, I have no control over that part. I would update it if I could. I will also note that if I comment out the see line, it doesn't throw an error, but I can't select anything and if I sort, the list clears. Which I found a similiar problem and solution on perlmonks for, but it did not work for me.
        I'm not sure how it would become empty randomly.

        Yeah, me neither, but since you left out any inkling of where @dispRes and %hash come from, or how they are generated, or what might be in them, I am reduced to making wild guesses and suppositions. Having undefined column headings gives me an error similar to what you reported but I am running perl 5.16.1 so it may be different in newer Perls. Try running the following and see if your error is the same. If so, my previous comment stands, if not, well, sorry, my mind reading is not up to snuff.

        use warnings; use strict; use Tk; my %w; $w{mw} = MainWindow->new; $w{lb} = $w{mw}->Scrolled( qw/MListbox -selectmode single -scrollbars oe -font small / )->pack(-expand => 1, -fill => 'both'); for my $x (qw//) { #for my $x (qw// || 'oops') { #for my $x (qw/a b c/) { $w{lb}->columnInsert('end', -text => $x ) ; } for (1 .. 10){ my @row = ($_, $_, $_,); $w{lb}->insert('end', \@row); $w{lb}->see('end'); $w{lb}->update; } MainLoop;

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1018203]
Approved by ww
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (12)
As of 2014-07-28 22:14 GMT
Find Nodes?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:

    Results (210 votes), past polls