building an array of hashes from MP3::Info

Discussion in 'Perl Misc' started by shambolic, Feb 21, 2004.

  1. shambolic

    shambolic Guest

    Hi,

    a few newby questions on building more complex data structures, if
    that's ok.

    i want to find duplicate mp3 files on my hardrive based on near
    matches for track title (TITLE) and Filename using MP3::Info.

    i have array @mp3s, of all the mp3 files on my drive, and looping
    through that get a hash of mp3 tags for each file (%hash). i then push
    %hash into an array, which i can loop through to compare duplicates,
    etc.


    so something along the lines of:

    use warnings;
    use strict;
    use MP3::Info;

    # == snip: build @mp3s using File::Find ==

    for my $file(@mp3s) {
    next unless /mp3/;

    # create hash with tag metadata
    print "trying to get tag for:$file\n\n";
    my $tag = get_mp3tag("$file") or die "no TAG info: $!";
    my %hash= %$tag;

    # create array of hashes
    push my @files, {%hash};

    # loop through array of hashes

    for my $i (0 ..$#files) {
    for my $element (keys %{ $files[$i] } ) {

    # insert find duplicate code here.

    print "$element is $files[$i]{$element}\n";
    }
    }

    so my questions are:
    * are there any modules that would do this better?
    * is it better to use an array of hashes or a hash of hashes (i've
    found it easier to use the array)?
    * what is the best way to match approximate values for filenames and
    TITLES? maybe String::Approx?
    * any other tricks i've (probably) missed with respect to design or
    approach?

    many thanks in advance

    j
     
    shambolic, Feb 21, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Daniel Dyer
    Replies:
    6
    Views:
    19,945
    Knute Johnson
    Jan 22, 2006
  2. Asle Frantzen

    Mp3-player - how to play an mp3?

    Asle Frantzen, Jul 8, 2003, in forum: C++
    Replies:
    5
    Views:
    672
    Kelsey Bjarnason
    Jul 22, 2003
  3. kazaam
    Replies:
    12
    Views:
    278
    Matthias Wächter
    Sep 13, 2007
  4. Matt Brooks
    Replies:
    16
    Views:
    228
    Matt Brooks
    Sep 16, 2009
  5. Tim O'Donovan

    Hash of hashes, of hashes, of arrays of hashes

    Tim O'Donovan, Oct 27, 2005, in forum: Perl Misc
    Replies:
    5
    Views:
    217
Loading...

Share This Page