in reply to file (mp3) list shown on website as links

Or you could be lazy and let Find::File do all the recursion and hard work.
use strict; use File::Find; #path can be relative to script dir or absolute path my $MP3ROOT = 'my_music'; #my $MP3ROOT = 'C:\\My Documents\\My Music'; #regex is case insensitive my $MP3SUFFIX = '.mp3'; my $PREFIX = 'http://www.homepage.org/'; #my $PREFIX = 'C:\\My Documents\\'; @ARGV = @ARGV || ( $MP3ROOT ); find( sub { if ( ( $File::Find::name =~ /$MP3SUFFIX$/i ) and ( $File::Find::dir !~ /^\./ ) ) # discard .hidden dirs { print "<a href=\"$PREFIX$File::Find::name\">$_</a>\n"; } } , @ARGV );
Someone correct me if I'm wrong but this eliminates the need to keep track of operating system dependent file delims, too, doesn't it?

Replies are listed 'Best First'.
Re: Re: file (mp3) list shown on website as links
by Nimster (Sexton) on Dec 23, 2000 at 22:35 UTC
    Actually, I've tried using File::Find at first, however, I'm a newbie to perl, and despite using many resources ranging from help from monks, perldoc, and Sams books (Yes, I know, I'll buy the Camel 3rd edition soon...), I just didn't understand how to use it. Thanks, your way is obviously superior. I'll vote ++ on it when I get my votes back (done for the day. :) ) -Nimster Freelance writer for GameSpy industries LTD. (www.gamespy.com)
      The Camel (3rd) is usually great. Perldoc is usually quite informative. But in the case of File::Find, they are both sorely lacking. There isn't much to File::Find, and even that is sparsely explained in every source I checked. I had to do a lot of learning myself to get that script together-- I'd never used the module before either.
        The docs for File::Find are ludicrously bad. The first example you ever see is:
        sub wanted { /^\.nfs.*$/ && (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) && int(-M _) > 7 && unlink($_) || ($nlink || (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_))) && $dev < 0 && ($File::Find::prune = 1); }
        However, if you look right at the bottom, you'll see a snippet like:
        sub wanted { -l && !-e && print "bogus link: $File::Find::name\n"; }
        which is really what you want to copy...

        Tony