The definition of your hash has quite a few problems, such as missing comma, missing end }, misusing = where needs =>. Also top level "Projects" is useless, unless you have something else at the same level (which you didn't show)
Here is an example as how you can go through subcomponents of softwares:
use Data::Dumper; use strict; use warnings; my %projects = ( Projects => { "Project1" => { version => "3.41", status => "nul", components => { "Software" => { name => "controller", label => "RC_1.01", subComponents => { "Database" => { version => "1.01", }, "SerialComms" => { version => "2.13", } } }, "Firmware" => { name => "I/O Interface", label => "RC_1.21", } } }, "Project2" => { }, "Project3" => { } } ); for my $project_key (keys(%{$projects{"Projects"}})) { print "$project_key:\n"; my $project = $projects{"Projects"}->{$project_key};#this looks no +t necessary here, but in more complex code, it does help to simplify +things if (defined($project->{"components"}{"Software"})) { for my $subcomponents_key (keys(%{$project->{"components"}{"So +ftware"}{"subComponents"}})) { print $subcomponents_key, ":\n"; print Dumper($project->{"components"}{"Software"}{"subComp +onents"}{$subcomponents_key}); } } }
this gives:
Project3: Project1: Database: $VAR1 = { 'version' => '1.01' }; SerialComms: $VAR1 = { 'version' => '2.13' }; Project2:
In reply to Re: Accessing multi-level hashes
by pg
in thread Accessing multi-level hashes
by carcassonne
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |