in reply to Accessing nested elements

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

Replies are listed 'Best First'.
Re^2: Accessing nested elements
by Anonymous Monk on Sep 29, 2009 at 07:31 UTC
    I prefer the perltidy version ( i also prefer a final trailing comma)
    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, );

      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, );

      DONE! :-), Thank you both for this one! Mucho easier to read.

      -Enjoy

Re^2: Accessing nested elements
by Anonymous Monk on Sep 29, 2009 at 08:59 UTC
    Beth, Thank you... The ultimate goal is to create the neatest slickest data structure of all mp3's found, that one could then sort (all elements, by any element), print, edit, etc... etc... This was my first attempt, I am very new to Perl, my first line of Perl was on 08/26/2009!

    Any more pointers are surely welcome.

    In reality no serious goal other than brain food!

    This just happens to be something that I can make use of to learn with, I have a few mp3's :)

    Thanks

    -Enjoy
    fh :_)~