HJO has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|