If you want to figure this out yourself, one thing that's helpful is to use e.g. Data::Dump to show the data structure. So for example, immediately after foreach my $planet (keys %$h_ref){, add dd $planet, $h_ref->{$planet}; to look at what you're dealing with at that point. You'll see that $planet is a string (the key of the hash), and that $h_ref->{$planet} (the value of the hash) is the hash reference that you should be dereferencing on the next line, i.e. foreach my $aa (keys %{ $h_ref->{$planet} }), and you have the same issue on the following line.

Extra credit: Because you're using Prototypes in sub base_code (\%), when you write base_code (%codes);, that is actually being translated by Perl to &base_code(\%codes). My recommendation would be to not use prototypes (sub base_code {...) and instead call the sub as base_code(\%codes);. See my recent post Fun with Prototypes for a demonstration of one of the problems with prototypes.

Update: Just a minor note: since hashes are unordered, keys will return the keys of the hash in an apparently random order. If you want your output to be consistent across different runs of the program, you could use foreach my ... (sort keys %...).


In reply to Re: printing complex data structures by haukex
in thread printing complex data structures by ic23oluk

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.