I have an Array of Hashes in a Hash that looks like this:
$var = {
'items' => [
{
'name' => 'name1',
'type' => 'type1',
'width' => 'width1',
},
{
'name' => 'name2',
'type' => 'type2',
'width' => 'width2',
},
{
'name' => 'name3',
'type' => 'type3',
'width' => 'width3',
}
]
};
I wrote the following code to get the values from a file.
my @members = ("name" => $name,
"type" => $type,
"width" => $width);
$rec->{$items} = [ @members ];
push @var, $rec;
I am not sure how to retrieve the values from this data structure.
I saw the solution in Iterate through Array of Hashes in a Hash in Perl. But I did not understand it. I am not sure what was $filelist that they had mentioned in the code.
foreach my $file (@{ $filelist{file} }) {
print "path: $file->{pathname}; size: $file->{size}; ...\n";
}
I am new to perl and please provide me details in your reply.
$varis a reference to a hash, and one of the elements of that hash (the only one so far) is theitemsarray. Do you need to have any other elements besidesitemsin that hash?