#!/usr/bin/perl -slw use strict; use warnings; use Data::Dumper; my %length; my %songs; opendir DH, "Y://perlscripts2/software/perl2/music" or die $!; # open current directory while($_ = readdir(DH)){ # don't evaluate special dirs '.' & '..' next if $_ eq "." or $_ eq ".."; if ($_ =~ /\.txt/){ chomp $_; my ($artist, $song_title) = split '-', $_, 3; $length{$artist}{$artist} = $artist; $length{$artist}{$song_title} = $song_title; print "$_"; # print this file/directory's name } # as a by-product of readdir; use the file's stat info # to check whether this is indeed a regular file we can # open for reading/further processing if (-f $_) { open FH, "<$_" or die $!; print "output for file: $_\n"; while (my $line = ) { print "$line\n"; if ($line =~ /\.txt/){ my($album, $minutes, $seconds, $genre) = split ':', $line, 4; $songs{$album} = $album; $songs{$minutes} = $minutes; $songs{$seconds} = $seconds; $songs{$genre} = $genre; print $album, "\n"; } close FH; } } }closedir DH; foreach my $artist ( sort keys %length ) { print "$artist is the name of the Artist\n"; } foreach my $album ( sort keys %songs ) { print "$album is this now\n"; }