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

I have several widgets displayed including a scrollable listbox and some scrollable text boxes. If a user clicks in one of my textboxes and begins to use the down arrow key when the textbox is empty, perl throws "Use of uninitialized value in numeric ne (!=) at ...Text.pm line 1223" I tried to duplicate this with a small example, but
use Tk; my $mw = MainWindow->new(); $mw->Scrolled('Text')->pack(); $mw->Text()->pack; MainLoop;
does not display the problem for either the Scrolled Text or the simple Text, so I figured the problem lied in my personal bindings of <Up> and <Down>. I removed the bindings and it stilled was there. I was able to duplicate the issue using the widget demo "widget". If you run "widget" and click on "1. Basic editable text." and delete all of the text in the text widget. You can replicate it by now down-arrowing. Anyone seen/solved this before I start digging around into how Nick/Greg handled this binding?

Replies are listed 'Best First'.
Re: uninitialized value using a Tk Text widget
by zentara (Cardinal) on Sep 02, 2008 at 20:30 UTC
    I think it's a weird bug in the way a common $TOP window is used in the widget demo. I saw the bug exactly as you described it, in the widget demo; BUT I took the exact code out of the demo and put it into a standalone window... and there is no problem. So I'm guessing the Text.pm could use an $self->update, or something similar) to get the scrollbars to reset their internal marker to 0,0. It seems that the up/down arrows are trying to define the next/previous line in that sub at 1223, but after deleting all text, there is no next previous line, and the Text widget (or the Scrolled element) wasn't notified because of the way the widget demo is windowed.

    You might ask on comp.lang.perl.tk.

    The following code is a chopped down version, and dosn't show the problem.

    By The Way, Nick is passed away, and Slaven Rezsic has pretty much taken over..... he reads comp.lang.perl.tk when he can.


    I'm not really a human, but I play one on earth Remember How Lucky You Are
Re: uninitialized value using a Tk Text widget
by shmem (Chancellor) on Sep 02, 2008 at 20:30 UTC
    "Use of uninitialized value in numeric ne (!=) at ...Text.pm line 1223"

    Well, something must be going wrong in Text.pm on line 1223. Can't say what, you provide too little information. What version of Tk? What platform? Just posting the sub the barfing line is in (and marking the line) would also help.

    I couldn't reproduce that with my 'widget' and 'widget_lib'-collection (perl-Tk-804.028; perl5.8.8; Fedora7).

Re: uninitialized value using a Tk Text widget
by thundergnat (Deacon) on Sep 03, 2008 at 17:11 UTC

    That is a bug in code that tries to track the relative position of the insertion cursor when arrowing up/down through text using a proportional font. Under certain conditions, it comes up with an undefined index value which causes that warning.

    FWIW, the code in the current version on CPAN has that particular comparison wrapped in a "no uninitialized" block. In other words, it's already fixed in the current version.

    While rooting around in the source though, I noticed that a bug I had reported and gotten fixed several years ago has reemerged. Someone backed out the patch for some reason and now the bug is back.

    Sigh.

    See this thread.