Shadowsong, this is what I came up with. The directory is being read and information is being stored in memory, but I'm have having trouble opening the .txt files to read the data in those files. I thought I was doing it the right way by using hashes to keying a value. But, it is still not reading the data in the .txt file. Am I doing something wrong or am I still not reading what is in the file?
#!/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 = <FH>) {
print "$line\n";
if ($line =~ /\.txt/){
my($album, $minutes, $seconds, $genre) = split ':', $l
+ine, 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";
}
Thanks, Brandon
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|