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

In reply to undefined value as a HASH reference?? by ryddler

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.