#!/usr/bin/perl -l use strict; use warnings; use Data::Dumper; my ($id,%length); my $fh1 = "The Bouncing Souls-True Believers.txt"; 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 ".."; 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 ($_ = $fh1) { open FH, "<$_" or die $!; print Dumper $_; print "output for file: $_\n"; while (my $line = ) { chomp $line; print $line; if ($line=~ /\.txt/){ my ($artist, $song_title) = split '-', $line, 3; $length{$id}{artist} = $artist; $length{$id}{song_title} = $song_title; } elsif (my $row =~ /\:/){ chomp $row; my ($album, $minutes, $seconds, $genre) = split ':', $row, 4; $length{$id}{album} = $album; $length{$id}{minutes} = $minutes; $length{$id}{seconds} = $seconds; $length{$id}{genre} = $genre; } else{ print "Could not open file $_\n"; } }close FH; } foreach my $artist ( sort keys %length ) { print "$length{$id}{artist} is the name of the Artist\n"; print "$length{$id}{song_title} is the name of the song\n"; print "Album is $length{$id}{album} \n"; print "Album minutes is $length{$id}{minutes} \n"; print "Album seconds is $length{$id}{seconds} \n"; print "Album genre is $length{$id}{genre} \n"; }