Help with a perl script?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • David K. Worman

    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
    # ackhayman@hotma il.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();

  • David K. Worman

    #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
    # ackhayman@hotma il.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();

    Comment

    • John Bokma

      #3
      Re: Help with a perl script?

      David K. Worman wrote:
      [color=blue]
      > 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.[/color]

      you mean cat *.m3u >> masterlist.m3u ?
      [color=blue]
      > #
      > # So far this script doesn't exactly work as planned.
      > #
      > # David K. Worman
      > # ackhayman@hotma il.com
      > ############### #########
      >[/color]

      add use strict; here.

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

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

      you open for *writing*
      [color=blue]
      > while (<PLIST>) {[/color]

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

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

      this is a constant, lift it out of the while.
      [color=blue]
      > print PLIST "$path$song ";
      > }
      > close(FLIST);
      > }
      > close(PLIST);
      > system("rm $FLIST");[/color]

      read about "unlink"
      [color=blue]
      > die();
      >[/color]


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


      Comment

      • David K. Worman

        #4
        Re: Help with a perl script?

        On Mon, 22 Sep 2003 08:46:18 +0200, John Bokma wrote:
        [color=blue]
        > David K. Worman wrote:
        >[color=green]
        >> 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.[/color]
        >
        > you mean cat *.m3u >> masterlist.m3u ?
        >[color=green]
        >> #
        >> # So far this script doesn't exactly work as planned. #
        >> # David K. Worman
        >> # ackhayman@hotma il.com
        >> ############### #########
        >>
        >>[/color]
        > add use strict; here.
        >
        >[color=green]
        >> $PLIST = "/home/dkworman/.gnome-desktop/playlist.m3u"; $FLIST =
        >> "/home/dkworman/.gnome-desktop/filelist.m3u"; system("rm $PLIST");
        >> system("cat /misc/media/*.m3u > $FLIST");[/color]
        >
        > This does probably not do what you want.
        >[color=green]
        >> open(PLIST, ">$PLIST") || die "Can't open $PLIST: $!n";[/color]
        >
        > you open for *writing*
        >[color=green]
        >> while (<PLIST>) {[/color]
        >
        > And start to read
        >[color=green]
        >> open(FLIST) || die "Can't open $FLIST: $!n"; while (<FLIST>) {
        >> chomp;
        >> ($song = $_);[/color]
        >
        > why don't you read in $song in the while? You make the code unreadable
        > this way
        >[color=green]
        >> $path = "/misc/media/";[/color]
        >
        > this is a constant, lift it out of the while.
        >[color=green]
        >> print PLIST "$path$song ";
        >> }
        >> close(FLIST);
        >> }
        >> close(PLIST);
        >> system("rm $FLIST");[/color]
        >
        > read about "unlink"
        >[color=green]
        >> die();
        >>
        >>[/color][/color]

        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

        Comment

        Working...