I have the code that can work fine for it own but when i combine with another function it show this error message " Tk::Error: Can't use an undefined value as a HASH reference at open_gui.pl line 231.". Line 231 is this line "my $output->{$count} =unpack('C',getc($otp));" Below is my code
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);
}
This is part of the code, the upper part of code no showing here is mainly the tk to build the GUI. This subroutine without combine with Tk function not showing here can work fine by self putting the binary file name to $otp but when i want to get the file from input of GUI it show the error. Any one can help for this? Thanks