G'day all, In need of ya'all's wisdom!

I have created this mess, yet fail to be able to get back at the nested elements.
<At the very end of the script is the cleaned up attempt>

I would explain the structure but don't know how to convey it
<The picture's in my mind and I can't get it out, Arrrg! >
The best place to get the structure is in sub HashMPEG.

Could I get a kick in the right direction please!

Also Other ideas/methods/concepts welcome!

To run the following code, TagLib 1.5 and Audio-TagLib-1.50_01 is required.
The '$MusicRoot' will also need to be edited to your needs

#!/usr/bin/perl use warnings; use strict; ###################################################################### # # BCE Project 19, Exercise accessing nested data # # Search for *.mp3, build structure of each mp3's info. # # print structured info # my $Filename = '\*.mp3'; my $MusicRoot = '/Your/Music/Location'; # no trailing slash # REQUIRES TagLib 1.5 avaliable at # REQUIRES Audio-TagLib-1.50_01 avaliable at cpan.org use Audio::TagLib::MPEG::Properties; use Data::Dumper; # For testing $Data::Dumper::Indent = 1; # For testing # Subs expect (Audio::TagLib::MPEG::File->new('Filename')) sub _Get_Artist { my $t = shift; return $t->tag()->artist()->toCSt +ring(); } sub _Get_Album { my $t = shift; return $t->tag()->album()->toCStr +ing(); } sub _Get_Title { my $t = shift; return $t->tag()->title()->toCStr +ing(); } sub _Get_Comment { my $t = shift; return $t->tag()->comment()->toCS +tring(); } sub _Get_Genre { my $t = shift; return $t->tag()->genre()->toCStr +ing(); } sub _Get_Year { my $t = shift; return $t->tag()->year(); } sub _Get_Track { my $t = shift; return $t->tag()->track(); } sub _Get_Length { my $t = shift; return $t->audioProperties->lengt +h(); } sub _Get_Bitrate { my $t = shift; return $t->audioProperties->bitra +te(); } sub _Get_Samplerate { my $t = shift; return $t->audioProperties->sampl +eRate(); } sub _Get_Channels { my $t = shift; return $t->audioProperties->chann +els(); } # Sub expects ('Filename') sub HashMPEG { my $f = shift; my %Artist; my %Album; my %Title; my %TagInfo; my $m = Audio::TagLib::MPEG::File->new($f); my %TagsMPEG = ('comment' => \&_Get_Comment, 'genre' => \&_Get_Genre +, 'year' => \&_Get_Year, 'track' => \&_Get_Track, 'length' => \&_Get_ +Length, 'bitrate' => \&_Get_Bitrate, 'samplerate' => \&_Get_Samplerat +e, 'channels' => \&_Get_Channels); for my $t (keys %TagsMPEG) { $TagInfo{$t} = $TagsMPEG{$t}->($m); } $Title{_Get_Title($m)} = \%TagInfo; $Album{_Get_Album($m)} = \%Title; $Artist{_Get_Artist($m)} = \%Album; return \%Artist; } sub HashFiles { my $d = shift; my $f = shift; my %FH; my @flist = `find $d -type f -name $f`; if ($#flist) { for my $t (@flist) { chomp $t; $FH{$t} = HashMPEG $t; } } return %FH; } my %FilesHash = HashFiles $MusicRoot, $Filename; # for testing #print Dumper(\%FilesHash); for my $File (keys %FilesHash) { print "File : " . $File . "\n"; }

Desired Output, or whatever explains access to the nested elements the best.

File : /Common/Music/Stevie Ray Vaughan and Double Trouble/Live +Alive/03-Pride and Joy.mp3 Artist : Stevie Ray Vaughan and Double Trouble Album : Live Alive Title : Pride and Joy Comment : Genre : Blues Year : 1986 Track : 3 Length : 304 Bitrate : 256 Samplerate : 44100 Channels : 2

Dumper output

'/mnt/RaidOne/Music/Stevie Ray Vaughan and Double Trouble/Live Alive +/03-Pride and Joy.mp3' => { 'Stevie Ray Vaughan and Double Trouble' => { 'Live Alive' => { 'Pride and Joy' => { 'bitrate' => 256, 'channels' => 2, 'track' => 3, 'samplerate' => 44100, 'genre' => 'Blues', 'length' => 304, 'comment' => '', 'year' => 1986 } } } },

Thanks
-Enjoy


In reply to 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.