470,619 Members | 1,863 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,619 developers. It's quick & easy.

Help with a perl script?

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
# ac*******@hotmail.com
########################

$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();

Jul 19 '05 #1
3 3353
#!/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
# ac*******@hotmail.com
########################

$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();
Jul 19 '05 #2
David K. Worman wrote:
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
# ac*******@hotmail.com
########################

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"
die();

--
Kind regards, virtual home: http://johnbokma.com/ ICQ: 218175426
web site hints: http://johnbokma.com/websitedesign/
John I count my toes ~ one to ten ~ I meditate ~ and feel the Zen
Jul 19 '05 #3
On Mon, 22 Sep 2003 08:46:18 +0200, John Bokma wrote:
David K. Worman wrote:
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
# ac*******@hotmail.com
########################

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"
die();


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
Jul 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Dennis Roberts | last post: by
1 post views Thread by Robert V | last post: by
1 post views Thread by Julia Bell | last post: by
3 posts views Thread by FLOTServer | last post: by
2 posts views Thread by MK | last post: by
5 posts views Thread by Louis | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.