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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.