Hi, all -- [I should probably note early on that I do have some preferences that don't match what many coders do but which I will very probably continue anyway, like how I place braces, but that I quite welcome perl style tips along with the rest of the answers begged below because lots of the other stuff that might drive people bananas *isn't* founded.]
I've been working on my mp3 scanner script, which will someday interface to a database, and I've run into a few questions. For those who want to see the whole script, it's at http://justpickone.org/davidtg/private/mp3-scan.pl and the playlist files it uses are at http://www.justpickone.org/davidtg/private/playlists/ as well. Here's the idea, though: The m3u data files contain paths, one per line, that might look like /mp3/artist/album/track /mp3/source/artist/album/track /mp3/source/subsource/artist/album/track where the first type are mine (no source), the second type came from someone else ("Dad", "Calix", "Downloads"), and the third type needed some other qualifier (only an address or source under Downloads so far, so I figure I can keep it that way going forward). The files were written in DOS format (\r\n or, I am more inclined to think, \n\r) and chomp doesn't work; instead I have to ... while (<>) { ... chop ; chop ; # strip \n\r (no chomp here) $fullpath = $_ ; # store for later ... which seems incongruous to me, but chomp sure didn't work until I saved a file in UNIX format and then fed it in -- but, of course, then using the double chop above not only strips the newline but the last actual char of the line. Is there a chomp that is smart enough to peel off \n\r if necessary and otherwise only \n or some other trick for this sort of thing, just so that I don't have to hard-code this to only work with DOS files? We can safely assume that we're working with text only, so if there's a trick that converts DOS to UNIX when necessary I'd take that... I can't modify $fullpath because I'll use it later, but for parsing I don't need the leading "/mp3/" part, and the only way I've found to get rid of it elegantly is ... @working = split(/\//,$fullpath) ; # cut path in pieces shift @working ; shift @working ; # strip [what was] /mp3 ... because it's either that or set $working to $fullpath and then =~ away the part we don't want and then split to @working. There just has to be a way to do this in one clever line, right? I'm all ears (well, eyes). The next bit actually parses out the pieces, including the source, with ... if ( $source eq $working[0] ) # same source { shift @working } # pop and continue else # new source { $source = "" ; # reset foreach (@allsources) # loop thru list { if ( /$working[0]/ ) # match a source? { $source = $working[0] ; last } # set it and drop out } } ($artist,$disk,$track) = @working ; # get the rest; away we go ... That works fine for zero or one source, but now I have to figure out how to pack the source back up into Downloads/addr or some such instead of having them in two pieces, and preferably without adding a $source2 var. Any ideas? TIA & HAND :-D -- David T-G * It's easier to fight for one's principles (play) [EMAIL PROTECTED] * than to live up to them. -- fortune cookie (work) [EMAIL PROTECTED] http://www.justpickone.org/davidtg/ Shpx gur Pbzzhavpngvbaf Qrprapl Npg!
msg25692/pgp00000.pgp
Description: PGP signature