Given the following XML::Simple object how would I copy one of the key values into a scalar assignment. The output below if from print Dumper($xmlobjectreturnedfrommodule);.
$VAR1 = {
'Address2' => {},
'City' => {},
'EmailAddress' => {},
'FName' => {},
'PostalCode' => {},
'LoginID' => {},
'StateProvinceChoice' => {},
'StateProvince' => {},
'Phone' => {},
'Country' => {},
'Site' => {},
'Address1' => {},
'PhoneExt' => {},
'LName' => {},
'OrganizationName' => {},
'Fax' => {}
};
Normally with a hashref I would just using something like the following:
print $xmlobjectreturnedfrommodule->{'LoginID'};
but it is returning the following HASH(0x1e32640) instead of the keys value in the hashref. Is there something about XML::Simple that is causing this or am I missing something?
What you are doing is right. Check this:
Output:
the
LoginIDis pointing to a hash reference which is essentially empty. If you modify the code as below, then you will get an empty hash:OutPut:
The way you are printing it (
print $xmlobjectreturnedfrommodule->{'LoginID'};), it will never return keys/values of thehasrefirrespective of whether thehashrefis empty or not. It will always return something likeHASH(0x1e32640)because that's what$xmlobjectreturnedfrommodule->{'LoginID'}is holding. In other words,{}is a hash reference.To print the keys/values, you need walk through the hash using a
forloop and retrieve keys/values.