Here's one way. Note there were some commas missing from your data structure.

Have a look at perldsc - complex data structures

#!/usr/bin/perl use strict; use warnings; my %HOH = ( Pegname1 => { section1 => { val1 => 'Value 1' }, section2 => { val2 => 'Value 2' }, section3 => { val3 => 'Value 3' }, }, Pegname2 => { section1 => { val1 => 'Value 1' }, section2 => { val2 => 'Value 2' }, section3 => { val3 => 'Value 3' }, } ); # question 2 - add a new value $HOH{Pegname3}{section1}{val1} = 'Value 1'; # question 2 - add a new record my $record = { section1 => { val1 => 'Value 1' }, section2 => { val2 => 'Value 2' }, section3 => { val3 => 'Value 3' }, }; $HOH{Pegname3} = $record; # question 1 - traverse the data structure for my $peg (sort keys %HOH){ print "$peg\n"; for my $section (sort keys %{$HOH{$peg}}){ print "\t$section\n"; for my $val (sort keys %{$HOH{$peg}{$section}}){ print "\t\t$val\n"; } } } __DATA__ ---------- Capture Output ---------- > "C:\Perl\bin\perl.exe" _new.pl Pegname1 section1 val1 section2 val2 section3 val3 Pegname2 section1 val1 section2 val2 section3 val3 Pegname3 section1 val1 section2 val2 section3 val3 > Terminated with exit code 0.
Update: Added 'add new record'
Update 2: Forgot to update ouput


In reply to Re: hash inside hash inside hash by wfsp
in thread hash inside hash inside hash by Anonymous Monk

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.