Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

undefined value as a HASH reference??

by ryddler (Monk)
on May 16, 2001 at 17:48 UTC ( [id://80884]=perlquestion: print w/replies, xml ) Need Help??

ryddler has asked for the wisdom of the Perl Monks concerning the following question:

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

Replies are listed 'Best First'.
Re: undefined value as a HASH reference??
by the_0ne (Pilgrim) on May 16, 2001 at 18:35 UTC
    I think people are missing the point. The poster is saying why when you use the hashref to set a value in the sheet range you get the error, but if you use the same hashref to set to a simple scalar ($legal) and then use that same scalar to set the sheet range there is no error. I'm a little lost on that one myself and the Hash problem post does not answer this question. Not sure what the difference is.
Re: undefined value as a HASH reference??
by azatoth (Curate) on May 16, 2001 at 18:06 UTC

      I did see that posting, but it doesn't answer my question. If you notice in my post I have given two examples of the offensive line, one of which works, and the other doesn't. Both are making assignments to something on the left side, but one causes an error, and the other doesn't.

      My question asks why the two are different, because it doesn't make any sense to me.

      I tried using the use warnings; and use diagnostics in my script (I already had -w), but the output results didn't give any more significant information that I could use. If I use the line that is commented out, #print_debug(Dumper $var_ref); I get a full printout showing all the variables to be quite defined!

      ryddler

Re: undefined value as a HASH reference??
by knobunc (Pilgrim) on May 16, 2001 at 18:23 UTC

    What does the Dumper($var_ref) call that you have commented out print? Maybe I haven't had enough coffee this morning, but it looks like the results element of $var_ref is not defined.

    -ben

      That's what my first thoughts were, and why I made that call in the first place, but here's what you'd see in the printout...
      $VAR1 = { 'filenumber' => '01-0052', 'results' => { 'Legal' => 'my lawyer made me do it', 'PriorpolDate' => undef, 'BldgLine' => undef, 'Deaths' => undef, 'Status' => 'OPEN', 'SearchType' => 'test', 'Notes' => 'this is where notes go…', 'Restrictions' => 'no restrictions', 'State' => 'IL', 'PIN2' => 'pin2yadayada', 'PIN3' => undef, 'City' => 'Champaign', 'LandVal' => '', 'SearchFromDate' => '2001-01-05 16:45:00', 'Drainage' => '1', 'Township' => 'village of champaign', 'EffectiveDate' => '2001-01-30 11:30:00', 'ImprovementVal' => '', 'Street' => '2408 Some Place', 'FileNumber' => '01-0052', 'Zip4' => '1234', 'Zip5' => '12345', 'OrderedBy' => undef, 'SearchedBy' => undef, 'MemberNumber' => '1234', 'Plat' => undef, 'LotSize' => 'a little bit smaller', 'Street2' => 'test street2', 'Easements' => undef, 'Exemptions' => '', 'Divorce' => undef, 'RequestDate' => '2001-01-30 11:30:00', 'MemberName' => 'W. Ghost Ryder', 'Probate' => undef, 'Wills' => undef, 'PIN' => 'assadsa', 'Access' => '100 feet of shoreline', 'TotalVal' => '' }, 'script' => 'template.pl', };


      ryddler

        Is it possible that the Range("A6") call is returning undef? Hoewver, that does not explain why it works after you assign it to a scalar. Perhaps the thing returned by Range() is a tied hash? Can you print out the result of the following:

        my $range = $Sheet->Range("A6"); print STDERR "Ref: ", ref($range), "\n"; print STDERR "Tied: ", tied($range), "\n";

        -ben

More Info: Re: undefined value as a HASH reference??
by ryddler (Monk) on May 17, 2001 at 18:07 UTC

    Further investigation reveals that running the script from the command-line (passing the CGI params) runs without problems. The assignment is made without fail.

    So now the situation becomes even more bizarre. It would seem that the failure to assign directly from the hash is because of security levels. That didn't seem to make any sense, because an assignment could still be made from a scalar, so what's the problem?

    On a hunch, I removed the -T from the Perl configuration in IIS, and tried the script again. This time it ran without any errors.

    I don't know much about Taint mode, but it seems to have been the reason for the assignment failures even though the error message said absolutely nothing about any tainted variables. "Undefined value as a HASH reference" doesn't seem even remotely close to tainted variables to me.

    Does any of this make sense to anyone? If so, could you fill me in?

    ryddler

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://80884]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2024-04-24 02:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found