Hello perl Monks,
I need to check to see if an xml hash element exists so i can create an array to post to variables for "stuff".
It sounds complex, but really its not. I'm sure i'm over-looking something simple.
Here is the gist of it:
I have xml returned to me (using SOAP::Lite) that looks something like this:
<xml version, encoding & SOAP Envelope header stuff...> <account> <accountId>001</accountId> <accountName>Account 001</accountName> <asset> <assetId>abcd</assetId> <assetName>Asset abcd</assetName> </asset> <asset> <assetId>wxyz</assetId> <assetName>Asset wxyz</assetName> </asset> </account> <account> <accountId>001</accountId> <accountName>Account 001</accountName> </account> </SOAP Envelope stuff...>
As you can see from the xml response, I am being returned account information that may have many or no "assets".
I am trying to perform actions (do stuff) with each 'account' + 'asset' sets.
Ultimately, I need to create an array like this:
for each (asset that exists) { $array = (accountId, accountname, assetId, assetName); (do stuff with the array); }
note - the 'accountId' and 'accountName' need to be carried through to each relevant 'asset'.
my script seems to die when it hits the 'account' with no 'asset'.
my $data1 = $xml->XMLin($xmlResponse); foreach my $account (@{$data1->{'account'}}) { my $acctName = $account->{'accountName'}; my $acctId = $account->{'accountId'}; if (defined $account->{'ns1:asset'}) { our $assetID = $account->{'asset'}->{'assetId'}; our $assetName = $account->{'asset'}->{'assetName'}; } else { print "\nIt didn't process\n"; } }
The out put looks like this:
Is the 'if (defined...' not doing what i think it should be doing?Bad index while coercing array into hash at c:/temp/parseit.pl line (e +quivelant of 7 in this case).
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |