Shadowsong, I appreciate all of the help that you have given me. The below code is what I was able to get to work and print out successfully. I did use some of the items that presented in your previous post. My issues were around setting up the hashes and keys. But, we will see what the instructor says about what I came up with. It is nice to know that there are folks out there willing help a newbie such as myself.
#!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 = <FH>){ 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}{m +inutes}:$length{$artist}{seconds} of music.\n"; }
Thanks, Brandon
In reply to Re^8: I need help with opening a directory and reading files in that directory.
by brawal128
in thread I need help with opening a directory and reading files in that directory.
by brawal128
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |