Help with a perl script?

D

David K. Worman

Here's what I'm working with so far, but all I wind up with is a 0 byte
file at the end, and the error;

"Filehandle PLIST opened only for output at ./medialist.pl line 20."

I know this error is pretty self explanatory, but for some reason I'm
unable to correct it, and I was under the impression that I was opening /
creating my file in the correct manner. Can someone take a look at my
code below and point me in the right direction?

TIA,

- dkw


#!/usr/bin/perl -w
#
# The purpose is to create one "master playlist" of my mp3 collection
# on my Gnome desktop, by cat'ing the auto-generated playlists created
# when I rip and encode my cd collection into said "master playlist"
# and then add the correct path to the final playlist, then cleanup after
# myself.
#
# So far this script doesn't exactly work as planned.
#
# David K. Worman
# (e-mail address removed)
########################

$PLIST = "/home/dkworman/.gnome-desktop/playlist.m3u";
$FLIST = "/home/dkworman/.gnome-desktop/filelist.m3u";
system("rm $PLIST");
system("cat /misc/media/*.m3u > $FLIST");
open(PLIST, ">$PLIST") || die "Can't open $PLIST: $!n";
while (<PLIST>) {
open(FLIST) || die "Can't open $FLIST: $!n";
while (<FLIST>) {
chomp;
($song = $_);
$path = "/misc/media/";
print PLIST "$path$song";
}
close(FLIST);
}
close(PLIST);
system("rm $FLIST");
die();
 
D

David K. Worman

#!/usr/bin/perl -w
#
# The purpose is to create one "master playlist" of my mp3 collection
# on my Gnome desktop, by cat'ing the auto-generated playlists created
# when I rip and encode my cd collection into said "master playlist"
# and then add the correct path to the final playlist, then cleanup after
# myself.
#
# So far this script doesn't exactly work as planned.
#
# David K. Worman
# (e-mail address removed)
########################

$PLIST = "/home/dkworman/.gnome-desktop/playlist.m3u";
$FLIST = "/home/dkworman/.gnome-desktop/filelist.m3u";
system("rm $PLIST");
system("cat /misc/media/*.m3u > $FLIST");
open(PLIST, ">$PLIST") || die "Can't open $PLIST: $!n";
while (<PLIST>) {
open(FLIST) || die "Can't open $FLIST: $!n";
while (<FLIST>) {
chomp;
($song = $_);
$path = "/misc/media/";
print PLIST "$path$song";
}
close(FLIST);
}
close(PLIST);
system("rm $FLIST");
die();
 
J

John Bokma

David said:
Here's what I'm working with so far, but all I wind up with is a 0 byte
file at the end, and the error;

"Filehandle PLIST opened only for output at ./medialist.pl line 20."

I know this error is pretty self explanatory, but for some reason I'm
unable to correct it, and I was under the impression that I was opening /
creating my file in the correct manner. Can someone take a look at my
code below and point me in the right direction?

TIA,

- dkw


#!/usr/bin/perl -w
#
# The purpose is to create one "master playlist" of my mp3 collection
# on my Gnome desktop, by cat'ing the auto-generated playlists created
# when I rip and encode my cd collection into said "master playlist"
# and then add the correct path to the final playlist, then cleanup after
# myself.

you mean cat *.m3u >> masterlist.m3u ?
#
# So far this script doesn't exactly work as planned.
#
# David K. Worman
# (e-mail address removed)
########################

add use strict; here.

$PLIST = "/home/dkworman/.gnome-desktop/playlist.m3u";
$FLIST = "/home/dkworman/.gnome-desktop/filelist.m3u";
system("rm $PLIST");
system("cat /misc/media/*.m3u > $FLIST");

This does probably not do what you want.
open(PLIST, ">$PLIST") || die "Can't open $PLIST: $!n";

you open for *writing*
while (<PLIST>) {

And start to read
open(FLIST) || die "Can't open $FLIST: $!n";
while (<FLIST>) {
chomp;
($song = $_);

why don't you read in $song in the while? You make the code unreadable
this way
$path = "/misc/media/";

this is a constant, lift it out of the while.
print PLIST "$path$song";
}
close(FLIST);
}
close(PLIST);
system("rm $FLIST");

read about "unlink"
 
D

David K. Worman

you mean cat *.m3u >> masterlist.m3u ?

add use strict; here.



This does probably not do what you want.


you open for *writing*


And start to read


why don't you read in $song in the while? You make the code unreadable
this way


this is a constant, lift it out of the while.


read about "unlink"

Code pasted all weird... it was (still is in my .pl) structured properly.
I'm just going to work with it more before coming back for help again.

- dkw
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top