in reply to it's been awhile . . .

Sorry to hear it...

Tough to help you out w/o seing the code you actually ran, any idea at this point where the script you used is? Was it exactly the code you originally asked about, or did you modify it from there?

-Blake

Replies are listed 'Best First'.
Re: Re: it's been awhile . . .
by ashaman (Sexton) on Oct 11, 2001 at 06:57 UTC
    naah, crap, forgot to mention, it's a test version, only prints what it should delete. but . . . i'm sure you could figure that out . . .
      what the--?! bloody hell, it posted it . . . *grumbles* ok, apparently i accidentally wrote a reply to my post instead of actually posting it and then replying, my bad . . . uhh, that is a reply to this: ok, this should be roughly like what i used. unfortunately, when my other computer died, it took all my files with it, so i don't have the actual script i used. but in tested, this one makes the same mistake. fortunately, i now have two 40GB hds, so i actually have room for back up. :)
      use strict; open(PLAYLIST, "<test.m3u"); my $dir = 'c:\my files'; opendir(FILES, "$dir"); open (TEST, ">test.txt"); my %playlist; my @filelist = grep {/\.mp3$/} readdir FILES; my $song; while(<PLAYLIST>) { chomp; if(not(/#/)) {$playlist{$_} = 1} } foreach $song(@filelist) { if(!exists $playlist{$song}) { print TEST $dir . "\\" . $song . "\n" } } closedir FILES; close PLAYLIST;
      btw, it's kinda been awhile since i used perl, and i don't remember exactly what {$playlist{$_} = 1} does, or how it does it. could someone refresh my memory? yeah, i know, i really should start commenting things
        Regarding the question: what does  {$playlist{$_} = 1 do: In a while(<PLAYLIST>) loop like yours, $_ contains the current record, so the statement you are wondering about sets a value of 1 in the hash for the current record. One reason I can see why this would fail is if you have trailing spaces in your input file, because e.g.'cool_song.mp3  ' is not the same as 'cool_song.mp3', which is what you will get from readdir. So this is how I would code the loop to avoid this:

        while (<PLAYLIST>) { s/#.*//g; #delete comments s/(^\s*|\s*$)//g; #delete leading and trailing spaces $playlist{$_} = 1 if /\.mp3$/; }

        To tell exactly what failed, of course, I would have to see also the input file.

        Don't be discouraged, be cautious - we all deleted precious files some time or other.

        pike