in reply to get value of hash hold by array and array hold by another hash
@{$h{CUST}} is an array of hash references. Just take each hash reference and de-reference the NAME parameter.
Update: Just wanted to show a couple of examples of how to print the OP's original structure. This C style for loop is not necessary. I guess toolic and I were composing our answers at the same time. The main thing is that we both got rid of an unnecessary level of de-referencing and although that is very, very important, proper use of Perl iterator operators is the reason that the "print" code got so much easier.#!/usr/bin/perl -w use strict; use Data::Dumper; my %h; push @{$h{CUST}}, { NAME => 'Mr.y', ADD => 'Hell', }; push @{$h{CUST}}, { NAME => 'Mr.z', ADD => 'Hell', }; push @{$h{ADMIN}}, { NAME => 'Mr.x', ADD => 'Hell', }; print Dumper \%h; foreach my $href ( @{$h{CUST}}) { print " CUST NAME: $href->{NAME} \n"; } __END__ $VAR1 = { 'ADMIN' => [ { 'NAME' => 'Mr.x', 'ADD' => 'Hell' } ], 'CUST' => [ { 'NAME' => 'Mr.y', 'ADD' => 'Hell' }, { 'NAME' => 'Mr.z', 'ADD' => 'Hell' } ] }; CUST NAME: Mr.y CUST NAME: Mr.z
#one way for initial structure foreach my $aref ( @{$h{CUST}}) { print " CUST NAME: $aref->[0]->{NAME} \n"; } #another way for initial structure foreach my $href (map{$_->[0]} @{$h{CUST}}) { print " CUST NAME: $href->{NAME} \n"; }
|
|---|