I think your data structure is not quite what you intended. When you make a more complex data structure, Dumper is your friend! One level of array is not necessary and I modified you code to take it out (run Dumper) on your code to see the difference. You were making an array of anon array references to anon hash references where each anon array only had one anon hash reference instead of simply an array of anon hash references.

@{$h{CUST}} is an array of hash references. Just take each hash reference and de-reference the NAME parameter.

#!/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
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.
#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"; }

In reply to Re: get value of hash hold by array and array hold by another hash by Marshall
in thread get value of hash hold by array and array hold by another hash by tart

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.