2008-11-25 103 views
3

下面是錯誤的:這些Tk :: Perl中的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; 
} 
+0

你能寫一個簡短的示例腳本來說明問題嗎?這可以幫助你找出誰是造成這個問題的原因。 – 2008-11-25 22:12:32

+1

您使用的是哪個版本的Perl和Tk? – 2008-11-25 22:15:45

+0

不管多短,我都會遇到同樣的問題。 Leon認爲這是圖書館的問題。 – Paul 2008-11-26 00:46:15

回答

4

錯誤消息本身是簡單的就夠了:在

使用未初始化值的$ id的散列元素在... Tk/After.pm第39行。

在刪除中使用未初始化的值$ id TE在... TK/After.pm線87

  • 「的未初始化值使用」意味着你使用的值與undef(未定義)的值。
  • $id是未初始化變量的名稱。
  • 「在散列元素中」表示您使用該值作爲散列鍵,例如$h{$id}
  • 「in delete」表示您使用該值作爲要刪除的散列鍵。例如delete $h{$id}
  • 「... Tx/After.pm」是發生錯誤的模塊。
  • 「第39行」和「第87行」是發生錯誤的行號(在模塊中)。

Tk :: After給Perl/Tk應用程序提供了回調調度。諸如「在500毫秒之後(或每隔500毫秒)運行此功能。」 $id是小部件上特定回調的標識符。

對警告做些什麼更難。在您提供的代碼中,我沒有看到任何明確的對Tk :: After的調用。有可能您的Tk安裝中存在觸發警告的錯誤。使用Tk 804.028在Perl 5.10下運行時,我沒有收到任何警告。

2

Someone else似乎有問題使用草莓Perl 5.10。我有一個印象,這是一個問題的庫,而不是你的代碼(早先在同一個函數中,哈希條目被刪除,但只有在定義了$id,因此顯然$id被定義不是保證)。

6

當我遇到這些問題時,我想找出是誰造成的。我把所有的警告成棧回溯,看看誰開始rukus:

 
use Carp; 
$SIG{__WARN__} = sub { &Carp::cluck } 
1

我看到有在x86 Cygwin的v5.10.0和804.028-1同樣的問題。有趣的是,如果代碼在調試器中執行,則不會出現問題,這表明代碼編譯/執行的方式不同。調試器內部和外部。

我懷疑底層的PerlTk代碼是正確的,問題在於Perl源代碼/可執行文件本身 - 應該將這種事情報告給誰?

MikeP

1

我得到同樣的錯誤。我相信這是因爲沒有顯示服務器在運行。更簡單的測試是在Cygwin提示符下輸入「widget」。它應該調出Tk小部件演示。如果我進一步發現任何問題,我會報告回來。