Hi,

I'm currently working on a project involving a Perl module which allows me to retreive data from a SAP system.

To do so, I give the Perl module some informations like the connexion parameters to the SAP system and the name of the SAP function-module I want to use (and his parameters as well).

The result is coming back as an Perl object, in which a structure (table of one row) is an hash table structured like key=field name and value = value, and a table an array of hash tables.

My problem is that sometimes, there are no data in the SAP system(not a bug, simply no data for the time period I'm specifying), but when it arrives in the Perl script, I'm suddently having the error Can't use an undefined value as a HASH reference at ./script.pl line 222..

What I'm looking for is a tip on how I could find out right after I retrieved my object that some of his arrays/hashes are empty... I tried to get "blanks" in the array before it was treated, but the array is erased totaly before beeing rewritten... I also tried to use the defined Perl function, but unsuccessfully (altrough I might have used it wrong...)

Here is the code I'm using to unpack my array :

@values = $rc->{parameters}->{$key}->{value}; my %valeur = %{$values[0][0]}; my @fields = keys(%valeur); my $nb_fields = scalar(@fields); for my $i (0 .. $nb_fields-1) { ${$struc_ref}[$i] = $fields[$i]; } #recuperation of the number of rows retrieved by the function-module my $nb_lignes = scalar(@{$values[0]}); #recuperation of the number of rows already in the table my $nb_lignes_base = scalar(@{$table_ref}); #display of data (for control) for my $i (0 .. $nb_lignes-1){ #number of rows retrieved by th F- +M for my $j (0 .. $nb_fields-1){ #number of fields in the table #storing data in a table ${$table_ref}[$nb_lignes_base+$i][$j] = $values[0][$i]{$fields +[$j]}; } }

The variables named $..._ref are referencies to two tables, struc stand for structure(a particular one row table), the variable $rc contains the massiv object that I get from my Perl module, (the 222 line is the one with "my %valeur = %{$values[0][0]};") and I appologize for other variables names, I'm french so I named them in an intuitive way for me, I tried to translate comments thought

I hope I gave you enough data to help me, if not please tell me and I will provide so... for any trouble with my variable names, I can also explain them ^^"

Regards


In reply to Error "Can't use an undefined value as a HASH reference" while working with generated objects by HJO

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.