Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Re: it's been awhile . . .

by ashaman (Sexton)
on Oct 11, 2001 at 06:57 UTC ( [id://118151]=note: print w/replies, xml ) Need Help??


in reply to Re: it's been awhile . . .
in thread it's been awhile . . .

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

Replies are listed 'Best First'.
Re: Re: Re: it's been awhile . . .
by ashaman (Sexton) on Oct 11, 2001 at 07:01 UTC
    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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://118151]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2024-04-23 17:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found