Help with a perl script?

Discussion in 'Perl' started by David K. Worman, Sep 22, 2003.

  1. 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
    #
    ########################

    $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();
     
    David K. Worman, Sep 22, 2003
    #1
    1. Advertising

  2. Re: Code pasted/posted weird above, trying again.

    #!/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
    #
    ########################

    $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();
     
    David K. Worman, Sep 22, 2003
    #2
    1. Advertising

  3. David K. Worman

    John Bokma Guest

    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
    > #
    > ########################
    >


    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
     
    John Bokma, Sep 22, 2003
    #3
  4. 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
    >> #
    >> ########################
    >>
    >>

    > 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
     
    David K. Worman, Sep 23, 2003
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Wet Basement
    Replies:
    1
    Views:
    2,556
    BobMonk
    Jul 15, 2003
  2. dpackwood
    Replies:
    3
    Views:
    1,841
  3. pj
    Replies:
    3
    Views:
    311
  4. Petterson Mikael

    Execute another perl script from my perl script

    Petterson Mikael, Jan 5, 2005, in forum: Perl Misc
    Replies:
    3
    Views:
    150
    Paul Lalli
    Jan 5, 2005
  5. Replies:
    20
    Views:
    814
    Gunnar Hjalmarsson
    Jan 18, 2005
Loading...

Share This Page