Tk::After 中的这些 Perl/Tk 错误是什么意思?
以下是错误:
$ 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.
这是 Perl/Tk 代码:
#! /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;
}
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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
当我遇到此类问题时,我想找出造成这些问题的原因。 我将所有警告转化为堆栈回溯,以查看谁发起了骚乱:
When I run into these sorts of problems, I want to find out who causes them. I turn all warnings into a stack backtrace to see who started the rukus:
错误消息本身很简单:
undef
(未定义)的值。$id
是未初始化变量的名称。$h{$id}
delete $h{$id}
Tk::After 为 Perl/Tk 应用程序提供回调调度。 诸如“在(或每)500 毫秒后运行此函数”之类的内容。
$id
是小部件上特定回调的标识符。如何处理这些警告就更困难了。 在您提供的代码中我没有看到任何对 Tk::After 的显式调用。 您的 Tk 安装中可能存在触发警告的错误。 在 Perl 5.10 和 Tk 804.028 下运行它时,我没有收到任何警告。
The error messages themselves are straightforward enough:
undef
(undefined).$id
is the name of the uninitialized variable.$h{$id}
delete $h{$id}
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.
其他人似乎在使用 Strawberry Perl 5.10 时遇到了这个问题。 我的印象是这是库的问题,而不是您的代码的问题(在同一函数的前面,哈希条目被删除,但前提是定义了
$id
,所以显然$ id
被定义并不能保证)。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).我还没有尝试过你的脚本,但看起来你可以通过从 shebang 行中删除
-w
来解决这个问题,这会打开全局警告,并添加use warnings;< /code>,仅在其范围内打开警告。 请参阅我应该转向有关详细信息,请参阅使用命令行开关或编译指示的 Perl 警告?。
更新:我已经尝试过,但也无法重现。
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 inuse 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.
我在 x86 Cygwin 上的 v5.10.0 和 804.028-1 上看到了同样的问题。 有趣的是,如果在调试器中执行代码,则不会出现该问题,这表明代码编译/执行的方式有所不同/??? 调试器内部和外部。
我怀疑底层 PerlTk 代码是正确的,问题出在 Perl 源代码/可执行文件本身 - 这种事情应该向谁报告?
迈克·P
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
我犯了同样的错误。 我相信这是因为没有运行显示服务器。 一个更基本的测试是简单地在 Cygwin 提示符下键入“widget”。 它应该会显示 Tk 小部件演示。 如果我发现任何进一步的情况,我会报告。
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.