Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2024-04-16 18:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found