#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my $filename; my $FH; my %length; my %songs; opendir DH, "./software/Perl2/Music" or die "Could not open directory!"; #open(my $file1, "<", "The Bravery-Believe.txt") or die "Could not open file $!"; while($filename = readdir(DH)){ if ($filename =~ /.txt/){ chomp $filename; my ($artist, $song_title) = split '-', $filename, 3; $length{$artist}{$artist} = $artist; $length{$artist}{$song_title} = $song_title; #print $artist,"\n"; #print $song_title,"\n"; } #elsif ($filename =~ /.txt/){ #open FH, "<", $filename or die "Could not open file '$filename' $!"; } print Dumper %songs; print Dumper %length; foreach my $artist ( sort keys %length ) { print "$artist is the name of the Artist\n"; } foreach my $album ( sort keys %length ) { print "$album is this now\n"; }