Hi mak.jordan!

Here are few observations on your code:

1. Looking at

$PG{$3}{"$1-$2"}{$cou} = $4;
you have three levels of keys in your hash. Therefore you only need three loops for accessing your data. Your innermost data ($4) is the value, not a key. So you should get rid of the innermost foreach loop.

2. A hint on debugging: it is much easier to develop the access of the hash step by step: First only write the outmost loop and check if the keys are teh ones that you are expecting. In the second step you add the second level, and check if the loop is working as expected (with a print statement) and so on. Then you'll find out where your code is wrong.

3. Having done this, you'll probably notice an error in the following line:

foreach $path3 ( keys %{$PG{$path1{$path2}}} )
Using $PG{$path1{$path2}}, you try to use $path1 as a hash, using the key $path2. And use the value of that hash-lookup as first-level-key in PG. However you want to access the second level of the $PG-hash. That would be done with $PG{$path1}{$path2}

HTH, Rata

In reply to Re: How to get my hash data using foreach loop?? by Ratazong
in thread How to get my hash data using foreach loop?? by mak.jordan

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.