Fellow monks,
I seek your wisdom with the following problem. I have created a package with a
single sub that I call from the main script. I pass a reference to a hash structure
that is built in the main script to the sub when it is called. The hash is built like this:
$vars = {
'script' => "template.pl",
'filenumber' => $filenumber,
'results' => $results_hash_ref,
};
and is passed like this:
ATGF::PDF::Charges::write_excel($vars);
The error I am receiving is "
Can't use an undefined value as a HASH reference at
C:/projects/metrosearch//ATGF/PDF/Charges.pm line 47."
Here's a snippet of the sub:
sub write_excel {
my $var_ref = shift;
#print_debug(Dumper $var_ref);
my $Excel = Win32::OLE->new('Excel.Application', 'Quit')
or die Win32::OLE->LastError;
$Excel->{Visible} = 1;
my $Book = $Excel->Workbooks->Open(
# Filename,[UpdateLinks],[ReadOnly],[Format],[Password],[WriteResP
+assword],
# [IgnoreReadOnlyRecommended],[Origin],[Delimiter],[Editable],[Not
+ify],[Converter],[AddToMru]
$ExcelFile,undef,0,undef,undef,undef,
undef,undef,undef,undef,0,undef,0
);
my $Sheet = $Book->Worksheets(1);
# Subject Property Column
my $address = "$var_ref->{results}{'Street'}\n";
$address .= "$var_ref->{results}{'Street2'}\n" if (length($var_
+ref->{results}{'Street2'}) > 0 );
$address .= "$var_ref->{results}{'City'}, " if (length($var_ref
+->{results}{'City'}) > 0 );
$address .= "$var_ref->{results}{'State'} " if (length($var_ref
+->{results}{'State'}) > 0 );
$address .= "$var_ref->{results}{'Zip5'}" if ($var_ref->{result
+s}{'Zip5'} != 0 );
$address .= "-$var_ref->{results}{'Zip4'}" if ($var_ref->{resul
+ts}{'Zip4'}!= 0 );
$Sheet->Range("A3")->{'Value'} = $address;
##########################################################
# line 47 from error message above is the following line #
##########################################################
$Sheet->Range("A6")->{'Value'} = $var_ref->{results}{'Legal'};
$Sheet->Range("B8")->{'Value'} = $var_ref->{results}{'PIN'};
$Sheet->Range("B9")->{'Value'} = $var_ref->{results}{'PIN2'};
$Sheet->Range("B10")->{'Value'} = $var_ref->{results}{'PIN3'};
...
}
As stated in the above snippet, this line:
$Sheet->Range("A6")->{'Value'} = $var_ref->{results}{'Legal'};
is the offending line (as are most of the rest below it if I comment them out one by one).
However, if I were to modify it like so.
my $legal = $var_ref->{results}{'Legal'};
$Sheet->Range("A6")->{'Value'} = $legal;
It works just fine. I don't understand why these are different in any other way than the
style in which they are written. Can anyone shed some light on this for me?
TIA
ryddler