#!usr/bin/perl -l use strict; use warnings; use Data::Dumper; my ($artist, $song_title, $filepath, %length,); $filepath = 'Y:/perlscripts2/software/perl2/music'; opendir DH, $filepath or die $!; chdir($filepath); while ($_ = readdir(DH)) { next if $_ eq "." or $_ eq ".." or $_ !~ m/\.txt$/; next unless -f $_ and -r $_; open FH, '<', $_ or die "could not open file: $_\n"; my ($artist, $song_title) = split /\-|\.txt/; $length{$artist}{artist} = $artist; $length{$artist}{song_title} = $song_title; while (my $line = ){ my ($album, $minutes, $seconds, $genre) = split ':', $line, 4; $length{$artist}{album} = $album; $length{$artist}{minutes} = $minutes; $length{$artist}{seconds} = $seconds; $length{$artist}{genre} = $genre; } close FH; } foreach my $artist ( sort keys %length ) { print "$length{$artist}{artist} has a total $length{$artist}{minutes}:$length{$artist}{seconds} of music.\n"; }