views:

735

answers:

7

Here are the errors:

$ perl ftper.pl
Use of uninitialized value $id in hash element at /usr/lib/perl5/vendor_perl/5.1
/i686-cygwin/Tk/After.pm line 39.
se of uninitialized value $id in hash element at /usr/lib/perl5/vendor_perl/5.1
/i686-cygwin/Tk/After.pm line 39.
se of uninitialized value $id in hash element at /usr/lib/perl5/vendor_perl/5.1
/i686-cygwin/Tk/After.pm line 39.
se of uninitialized value $id in hash element at /usr/lib/perl5/vendor_perl/5.1
/i686-cygwin/Tk/After.pm line 39.
se of uninitialized value $id in hash element at /usr/lib/perl5/vendor_perl/5.1
/i686-cygwin/Tk/After.pm line 39.
se of uninitialized value $id in hash element at /usr/lib/perl5/vendor_perl/5.1
/i686-cygwin/Tk/After.pm line 39.
se of uninitialized value $id in delete at /usr/lib/perl5/vendor_perl/5.10/i686
cygwin/Tk/After.pm line 87.
se of uninitialized value $id in delete at /usr/lib/perl5/vendor_perl/5.10/i686
cygwin/Tk/After.pm line 87.
se of uninitialized value $id in delete at /usr/lib/perl5/vendor_perl/5.10/i686
cygwin/Tk/After.pm line 87.
se of uninitialized value $id in delete at /usr/lib/perl5/vendor_perl/5.10/i686
cygwin/Tk/After.pm line 87.
se of uninitialized value $id in delete at /usr/lib/perl5/vendor_perl/5.10/i686
cygwin/Tk/After.pm line 87.
se of uninitialized value $id in delete at /usr/lib/perl5/vendor_perl/5.10/i686
cygwin/Tk/After.pm line 87.  

Here is the Perl/Tk code:

#! /usr/bin/perl -w

use strict;
use Tk;
use Tk::Scale;
use File::DosGlob 'glob';


#####################################################################
# Define variables                  #
#####################################################################
my $UserID;
my $Password;
my $BnsNode;
my $Status_msg = "BUILD SCRIPT!";

#####################################################################
# Window variables           #
#####################################################################
my $mw;
my $frmUserID;
my $lblUserID;
my $frmPassword;
my $lblPassword;
my $edtUserID;
my $edtPassword;
my $frmTop;
my $frmBig;
my $frmButtonLine;
my $btnExit;
my $btnSubmit;
my $lblStatus;
my $lblUnixNode;
my $frmUnixNode;
my $edtUnixNode;

#################################################################
# Main Logic          #
#################################################################
init_mainwindow();
MainLoop;



#################################################################
# init_mainwindow        #
#################################################################
sub init_mainwindow {
    $mw = MainWindow->new;
    $mw->title("BUILD");
    $mw->resizable(100, 100);
    $mw->geometry("+175+100");

    # Top Level frame for top section of form.
    $frmTop = $mw->Frame(-bd => 2, -relief => 'ridge')
     ->pack(-side => 'top', -fill => 'x', -pady => 3);


    $frmUserID = $frmTop->Frame(-bd => 2)->pack(
     -side => 'top', -fill => 'x');
    $lblUserID = $frmUserID->Label(-text => "Unix User ID:")
     ->pack(-side => 'left');
    $edtUserID = $frmUserID->Entry(-textvariable => \$UserID,
     -background => 'white')->pack(-side => 'left');


    $frmUnixNode = $frmTop->Frame(-bd => 2)->pack(
 -side => 'top', -fill => 'x');
 $lblUnixNode = $frmUserID->Label(-text => "BNS Number")
  ->pack(-side => 'left');
 $edtUnixNode = $frmUserID->Entry(-textvariable => \$BnsNode,
 -background => 'white')->pack(-side => 'left');


$frmPassword = $frmTop->Frame(-bd => 2)->pack(
 -side => 'top', -fill => 'x');
$lblPassword = $frmPassword->Label(
 -text => "Password:    ")->pack(-side => 'left');
$edtPassword = $frmPassword->Entry(-textvariable => \$Password,
 -background => 'white', -show => "*")
 ->pack(-side => 'left');



# Top Level frame for bottom section of form.
$frmButtonLine = $mw->Frame(-bd => 2, -relief => 'ridge')
 ->pack(-side => 'top', -fill => 'x', -pady => 3);
    $btnExit = $frmButtonLine->Button(-text => "Exit", 
     -command => \&close_mw, -width => 6)->pack(
     -side => 'right', -padx => 1);
     $btnSubmit = $frmButtonLine->Button(-text => "Run Script", 
 -command => \&execute_script, -width => 6)->pack(
     -side => 'right', -padx => 1);
    $lblStatus = $mw->Label(-textvariable => \$Status_msg,
     -borderwidth => 2, -relief => 'groove')
     ->pack(-fill => 'x', -side => 'bottom');

    $edtUserID->focus;

}


#####################################################################
# excute_script           #
#####################################################################
sub execute_script {
    unless (defined($UserID)) {
     update_status("Must enter a user id!");
     $edtUserID->focus;
     return 0;
    }
    unless (defined($Password)) {
     update_status("Must enter a password!");
     $edtPassword->focus;
     return 0;
    }

    update_status("$BnsNode ,$UserID ");
}

#####################################################################
# close_mw            #
#####################################################################
sub close_mw {
    $mw->destroy;
}


#####################################################################
# update_status           #
#####################################################################
sub update_status {
    my ($msg) = @_;

    $Status_msg = $msg;
    $lblStatus -> update;
}
+4  A: 

The error messages themselves are straightforward enough:

Use of uninitialized value $id in hash element at ...Tk/After.pm line 39.

Use of uninitialized value $id in delete at ...Tk/After.pm line 87.

  • "Use of uninitialized value" means that you used a value with a value of undef (undefined).
  • $id is the name of the uninitialized variable.
  • "in hash element" means that you used the value as hash key, e.g. $h{$id}
  • "in delete" means that you used the value as a hash key to be deleted. e.g. delete $h{$id}
  • "...Tx/After.pm" is the module where the error occurred.
  • "line 39" and "line 87" are the line numbers (in the module) where the error occurred.

Tk::After provides callback scheduling to Perl/Tk applications. Things like "run this function after (or every) 500 ms." $id is the identifier for a specific callback on a widget.

What do do about the warnings is harder. I don't see any explicit calls to Tk::After in the code you provided. It's possible that there's a bug in your Tk installation that's triggering the warning. I don't get any warnings when running it under Perl 5.10 with Tk 804.028.

Michael Carman
I liked your answer the best as far as explaining the problem . Though for a short term solution I am going to turn of warnings. I am running a cygwin port of Perl 5.10 with Tk 804.028. Maybe that is why I am seeing it and you are not.
Paul
+2  A: 

I haven't tried your script yet but it looks like you could solve this problem by removing the -w from the shebang line, which turns on global warnings, and adding in use warnings;, which only turns on warnings in its scope. See Should I turn on Perl warnings with the command-line switch or pragma? for details.

Update: I have tried it and I cannot reproduce it either.

Mr. Muskrat
This was hard because your answer really solved my problem as far what to do about it. But others really answered the why and because of the way the problem was worded I am going to have to go with Carman's answer.
Paul
+2  A: 

Someone else seems to have had that problem using Strawberry Perl 5.10. I'm having the impression it's an issue of the library, not your code (earlier in the same function, that hash entry is deleted, but only if $id is defined, so apparently $id being defined is not an guaranteed).

Leon Timmermans
+6  A: 
brian d foy
Is there a reason that isn't: $SIG{__WARN__} = \ ?
Leon Timmermans
I like that answer but the carman answer really answered the question.Though your answer provides me with a way to discover that on my own.
Paul
There's no reason it's not \ I just tend to type sub { } a lot, I guess.
brian d foy
+1  A: 

I'm seeing the same issue with v5.10.0 and 804.028-1 on x86 Cygwin. Interestingly, the problem does not appear if the code is executed in the debugger, suggesting a difference in the way code is compiled/executed/??? inside and outside of the debugger.

I suspect the underlying PerlTk code to be correct and that the problem lies in the Perl source/executable itself - who should this sort of thing be reported to?

MikeP

+1  A: 

I get the same error. I believe that it is because there is no display server running. A more basic test is to simply type "widget" at the Cygwin prompt. It should bring up the Tk widget demo. I will report back if I find anything further.

A: 

I am also seeing this error, but only when warnings from the Tk::After scope are allowed to bubble up. (that is, the -w flag instead of the "use warnings;" pragma.

I too am using Strawberry perl (perl 5, at that)

BTW: when I ditch the "-w" flag the warning goes away... :)

Hope this helps (or at least directs our searches a bit more)

Michael