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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |