Hi all, I have a PERL script in which I do the following: -call a subroutine to do some file initialization and stuff - return -initialize a hash (%hashname = (); ) -call a subroutine, passing a reference to the hash. In the subroutine I parse a bunch of data and eventually write to the hash thusly: $$hashname{$key1}{$key2}{$key3}{$key4} = $value; - call a second subroutine, passing a reference to the hash to it. Here's where the trouble starts..... Here's my subroutine:
sub GEN_HTML { + # generate HTML for form $mp3hash = shift; + # hash - parsed xml itunes data #print Dumper(\%{$mp3hash}); foreach $player (sort keys %{$mp3hash}) { foreach $collection (sort keys %{$mp3hash{$player}}) { print "DEBUG: the player is [$player] the collection is [$collection]\ +n"; foreach $thetrack ( sort keys %{$mp3hash{$player}{$collect +ion}}) { foreach $bute ( sort keys %{$mp3hash{$player}{$collect +ion}{$track_name}}) { print "$player - $collection - $thetrack - $mp3has +h{$player}{$collection}{$track_name}{$bute}\n"; } } } } return; }
If I uncomment the Dumper line, I get the expected data structure and data. If I put a print statement after the first foreach and print $player, I get the data I expect, however, I cannot get any of the data from the inner foreach loops to print. I'm pretty sure I just haven't figure out how to properly de-reference the keys in the inner loops, but I can't seem to figure out how to do this.... Oh, and if I put these loops up in main, everything works fine..... Any help? Thanks, bigtiny

In reply to Cannot dereference hash in subroutine.... by bigtiny

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.