in reply to How to access hash of arrays values using perl

Not sure what you mean by "access each element", since the elements seem to be a variety of different structures, but here's how to get into the structure a couple levels. For everyone else's benefit, I added something into that hole at the bottom and then ran this through Data::Dumper first and eliminated a bunch of the whitespace at the left side to clean it up.

use strict; use warnings; my $nested = { 'Systemreaction' => [ { 'Data' => 'x' }, { 'Data' => 'x' } ], 'Service' => [ { 'Customers' => [ { 'SW' => [ { 'Path' => '/work/servi +ce.xml', 'Service' => 'ASOC' } ] } ], 'Id' => 'SKRM', 'Name' => ' Control unit', 'Suppliers' => [ { 'SW' => [ { 'Path' => '/work/servi +ce.xml', 'Service' => 'b7a' }, { 'Path' => '/work/servi +ce1.xml', 'Service' => 'b7b' }, { 'Path' => '/work/servi +ce2.xml', 'Service' => 'b5' } ] } ], 'Des' => 'Control the current through the pipe' }, { 'Customers' => [ { 'SW' => [ { 'Path' => '/work/servi +ce.xml', 'Service' => 'SDCR' } ] } ], 'Id' => 'ADTM', 'Name' => ' Motor Drivers and Diognostics', 'Suppliers' => [ { 'HW' => [ { 'Type' => 'W', 'Path' => '/work/hardw +are.xml', 'Nr' => '18', 'Service' => '1' }, { 'Type' => 'B', 'Path' => '/work/hardw +are.xml', 'Nr' => '7', 'Service' => '1' }, { 'Type' => 'k', 'Path' => '/work/hardw +are.xml', 'Nr' => '1', 'Service' => '1' } ] } ], 'Des' => 'It delivers actual motor speed' } ] }; for my $service (@{$nested->{'Service'}}) { print "$service->{'Name'}\n"; } for my $system (@{$nested->{'Systemreaction'}}) { print "$system->{'Data'}\n"; }

Replies are listed 'Best First'.
Re^2: How to access hash of arrays values using perl
by veerubiji (Sexton) on Dec 15, 2011 at 22:03 UTC

    Sorry for not clearance post, I mean how to get nested elements, but I am facing difficult in getting "Type" and "Nr" values. can you help me with that, or give me some example.

    Thanks for your reply

      Using my previous definition for $nested:

      for my $service (@{$nested->{'Service'}}) { for my $suppliers (@{$service->{'Suppliers'}}) { for my $hw (@{$suppliers->{'HW'}}) { print "Type: $hw->{'Type'}\n"; print "Nr: $hw->{'Nr'}\n"; } } }