【发布时间】:2017-05-24 06:35:51
【问题描述】:
我有自己可以正常工作的代码,但是当我与另一个函数结合使用时,它会显示此错误消息“Tk::Error: Can't use an undefined value as a HASH reference at open_gui.pl line 231。 ”。第 231 行是这一行“我的 $output->{$count} =unpack('C',getc($otp));”下面是我的代码
sub main($$){
my $call_form = shift ;
my $file1 = shift -> get() ;
my $output={};
bless $output;
my $j =0;
my $i =0;
grab_file($output,$file1);
}
sub grab_file($$){
my $output=shift;
my $file = shift;
open(my $otp, '<' , "$file") or die "Error, File1 could not open\n";
open(my $input, "> info.txt") or die "Error, File3 could not open\n";
my $count = 0;
binmode($otp);
seek ($otp,829440,0);
for my $count (0..27648){
my $output->{$count} =unpack('C',getc($otp));
print $input "$output->{$count}\n";;
}
close ($input);
close($otp);
open(FILE4, ">data.txt") or die "Error, File4 could not open\n";
open ( my $input, '<', "info.txt" ) or die $!;
chomp ( my @file = <$input> );
print FILE4 join (" ",splice (@file, 0, 16)),"\n"while @file;
close($input);
close(FILE4);
}
这是部分代码,这里没有显示的代码的上半部分主要是构建GUI的tk。这个没有与此处未显示的 Tk 函数结合的子例程可以通过自行将二进制文件名放入 $otp 来正常工作,但是当我想从 GUI 的输入中获取文件时,它会显示错误。任何人都可以为此提供帮助吗?谢谢
【问题讨论】:
-
eval.in/803952 =>
use warnings;节省了一天。