in reply to Hashes hunt me even when I sleep....
#!/usr/bin/perl -w
$myFile = "/home/mydata/playlist.txt";
print "Content-Type: text/html\n\n";
print "<html><head><title>My Song List</title></head>\n";
print "<body>\n";
open(ALBUMS, "$myFile") or die "Can't open $myFile: $!\n";
while ($line = <ALBUMS>) {
($song, $artist, $album, $location) = split('\|', $line);
$songlist{$artist}->{$album} .= $song . "\+";
$locations{$song} .= $location . "\+";
}
foreach $artist (sort keys %songlist) {
print "<b>Artist:</b> ";
if (!$artist) {
print "\tNot Provided\n";
} else {
print "$artist\n";
}
foreach $album (sort keys %{$songlist{$artist}}) {
print "<blockquote>\n";
print "\t<b>Album:</b>";
if (!$album) {
print "\tNot Provided\n";
} else {
print "\t$album\n";
}
print "<blockquote>\n";
print "\t\t<b>Songs:</b><br>\n";
$i = 0;
@songs = split('\+', $songlist{$artist}{$album});
foreach $song (@songs) {
@thislocation = split('\+', $locations{$song});
foreach $location (@thislocation) {
++$i;
print "\t\t\t$i. <a href=\"http://$location\">$song</a><br>\n";
}
}
print "</blockquote></blockquote>\n";
}
}
Now, mind you that this is just a beginning, something to start on. I'm not sure if anybody else would do this the same way (probably not) but in this case it does a job. I'll throw later some search capabilities and off to fun we go!
P.S. What scares me the most is the fact that I haven't fully realized how I accomplished this task. I was playing with this code until I got it right. It's going to take some time before I feel comfortable with hashes, dereferencing and other "goodies." Meantime, I will enjoy what I have accomplished with you help! :-)
|
|---|