I have a problem with extracting an individual hash from an array of
hashes. I can't work out, or find elsewhere, the syntax for this.
Code as follows:
devices_array_oH is set up as array of hashes
I want to loop over all hashes in the array and to print the key value pairs for
each hash.
I have tried the following but get run-time errors:
my($num_devices, $idevice);
$num_devices = scalar (@devices_array_oH) ;
for ($idevice=0; $idevice < $num_devices; $idevice++)
{
my (%device_hash, $itemp, $key);
$itemp = $idevice + 1;
#
#--- Extract one element of array to local hash
#
%device_hash = $devices_array_oH[$idevice]; <----------- Flagged as
run-time error:
Reference found
where even size list expected
print " Details of device $itemp: ";
print "\n\n";
foreach $key (keys(%device_hash))
{
print (" $key \t $device_hash{$key} \n"); <---- Flagged
as run-time error
} use of
un-initialized value in concatenation
Presumably
due to above
print "\n\n";
print " ***** End of details for all devices ";
print "\n\n";
}
Just can't figure it out - any suggestions.
Thanks,
Charles.