如何将数组传递给Perl / Tk中的子程序

时间:2014-05-19 08:50:33

标签: perl perltk

作为标题,我可以知道如何将数组中的值传递给Perk / Tk脚本中的子例程吗?我尝试使用以下代码实现这一点但不知何故它会出错:

> Tk::Error: Can't call method "get" without a package or object reference at ll.ptk line 36.
 Tk callback for .frame1.button
 Tk::__ANON__ at /usr/pkgs/perl/5.14.1/lib64/module/default/x86_64-linux/Tk.pm line 251
 Tk::Button::butUp at /usr/pkgs/perl/5.14.1/lib64/module/default/x86_64-linux/Tk/Button.pm line 175

   (绑定到事件的命令)

Tk::Error: Can't call method "get" without a package or object reference at ll.ptk line 36.
Tk callback for .frame1.button
Tk::__ANON__ at /usr/pkgs/perl/5.14.1/lib64/module/default/x86_64-linux/Tk.pm line 251
 Tk::Button::butUp at /usr/pkgs/perl/5.14.1/lib64/module/default/x86_64-linux/Tk/Button.pm line 175

 (绑定到事件的命令)

我的代码: -

#!/usr/bin/perl
use Tk;
use strict ;
use warnings ;

my $mw = MainWindow->new;
my $mwf = $mw->Frame->pack ;
my $mwb = $mw->Frame->pack ;

my $a = "1" ;
my $b = "2" ;

$mwf->Label(-text => 'input',
-justify => 'left'
)->grid(-sticky => 'w', -column => 0, -row => 1);

my @input = () ;
my $waiver = $mwf->Entry(-width => 100,
        -background => "white",
        )->grid(-sticky => 'w', -column => 1, -row => 1);
        push @input, $waiver ;

$mwb->Button(
  -text => 'Run',
  -width => 50,
  -command => sub{printsub ($a, $b, \@input)} ,)
  ->pack (-side => 'left', -fill => 'x', -expand => 'yes') ;


MainLoop;

sub printsub {
my ($a, $b, $input) = @_ ;
my $a_val = $a->get ;
my $b_val = $b->get ;
my $input_val = @$input ;
print "\na: $a_val, b: $b_val c: $input_val\n" ;
#print "\na: $a, b: $b c: $input\n" ;
}

感谢。

0 个答案:

没有答案