I've been trying to read the following structure in Perl:
my %Homes = (
"Home 1" => [
'TYPE_OF_HOUSE' => "Villa",
'FIELD1' => ["1","2","3"],
'Field2' => ["2","3","4"],
'Field3' => ["3","4","5"],
],
"Home 2" => [
'TYPE_OF_HOUSE' => "Duplex",
'FIELD1' => ["1","2","3"],
'Field2' => ["2","3","4"],
'Field3' => ["3","4","5"],
],
"Home 3" => [
'TYPE_OF_HOUSE' => "Apartment",
'FIELD1' => ["1","2","3"],
'Field2' => ["2","3","4"],
'Field3' => ["3","4","5"],
],
);
By using the following:
my @data_Array;
my ($inner_Key,$key,$names_ref);
foreach $key (keys %Homes)
{
print("Inner values of house $key are:");
foreach $inner_Key ( @{$Homes{$key}})
{
if ($inner_Key != "TYPE_OF_HOUSE")
{
$names_ref = \@$inner_Key;
@data_Array = @{$names_ref};
print($data_Array[0]);
print($data_Array[1]);
print($data_Array[2]);
}
else
{
print($inner_Key);
}
}
}
I successfully printed the: "Home 1", "Home 2", but when trying to read the inner content, even though I used reference to an array, it didn't go well. What did I miss? My goal was to "identify" the type of field, and if it was TYPE_OF_HOUSE, then simply print it because it is not an array. Otherwise, print the inner content of its array.