#! perl -slw use strict; use Data::Dumper; my ($album_id,$track_id,$filepath,%music); $filepath = 'Y:/perlscripts2/software/perl2/music' opendir DH, $filepath or die $!; # magic one-liner to "fix" your path problems chdir($filepath); while(readdir(DH)){ # don't evaluate special dirs '.' & '..' # or anything that doesn't end in .txt next if $_ eq "." or $_ eq ".." or $_ !~ /\.txt$/; # explicitly test this item to see if it's a # regular file and if it's readable (notice the # use of the default filehandle test var '_') next unless -f $_ and -r _; # arrival here signifies we have a readable, # regular file. Extract its contents into a hash open FH, '<', $_ or die "could not open file: $_\n"; # use the actual filename to pull the album & artist my ($name, $artist) = split /\-|\.txt/; $album_id++; $track_id = 0; $music{$album_id}{ALBUM} = $name; $music{$album_id}{ARTIST} = $artist; while (my $line = ) { # the lines of this file are of the format # ::: my ($track, $minutes, $seconds, $genre) = split /\:/, $line; $track_id++; $music{$album_id}{$track_id}{TRACK}{TITLE} = $track; $music{$album_id}{$track_id}{TRACK}{DURATION} = [$minutes,$seconds]; $music{$album_id}{$track_id}{TRACK}{GENRE} = $genre; } close FH; } print Dumper \%music; __END__