Could you be more specific about what you want help with? It looks like you've gotten far enough to have useful dumper output. Do you need to learn how to pretty print it? Or are you expecting different contents your hash, for example, more than one author/title in your hash? Your project assignment looks like you are supposed to be working with what looks like a directory name ($MusicRoot) that perhaps contains many MPEG files.

In the meantime, here are some coding tips:

Your intent for %TagsMPEG would be clearer if you put one assignment per line, like this:

#I like commas at the beginning so that I know the line #is a continuation of the previous, but others like commas #at the end of each line. The main thing is one assignment #per line. my %TagsMPEG = ('comment' => \&_Get_Comment , 'genre' => \&_Get_Genre , 'year' => \&_Get_Year , 'track' => \&_Get_Track , 'length' => \&_Get_Length , 'bitrate' => \&_Get_Bitrate , 'samplerate' => \&_Get_Samplerate , 'channels' => \&_Get_Channels );

Also, you don't need to create a hash variable to assign a hash to a data element. You can nest hash keys directly, like this:

$Artist{_Get_Artist($m)}{_Get_Album{$m}}{_Get_Title{$m}}=\%TagInfo;

Finally, your current code creates and returns a hash with only one artist. Is this really what you want? Or did you want to build a hash with many artists? If you want to build up a hash with many artists, the best way is to pass HashMPEG() a reference to an artist hash rather than trying to create the artist hash inside HashMPEG(). It would look something like this:

sub HashMPEG { # assign parameters useful names # $hArtist is a hash reference my ($f, $hArtist) = @_; #... extract data from MPEG file # -> operator is used when working with hash references rather # than hashes $hArtist->{_Get_Artist($m)}{_Get_Album{$m}}{_Get_Title{$m}}=\%TagInf +o; # no need to return anything. artist is in hash reference # and caller has access to hash reference }

You may find it helpful to take a look at the following Perl documentation, perlreftut, perldata and perldsc.

Best, beth

Update: fixed misinterpretation of code


In reply to Re: Accessing nested elements by ELISHEVA
in thread Accessing nested elements 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.