http://qs321.pair.com?node_id=63657

astanley has asked for the wisdom of the Perl Monks concerning the following question:

Good afternoon everyone, I recently started a project just for grins that will act as a flexible search engine for a web page. In the script I statically provide the top directory to begin searching in and I'm trying to have the script compare the contents of every file under that directory with the user's query and return the matches. It works great for the top level directory but I can't figure the best way to traverse through the rest of the directory's under the top level. I saw a node discussing File::Find but am unsure if that module would perform what I need. Does anyone have any other suggestions? I want the script to be intelligent enough to traverse through as many directory's and levels as it can find rather than setting a static number for it to stop.
Adam

Replies are listed 'Best First'.
Re: traversing directory's
by athomason (Curate) on Mar 12, 2001 at 01:25 UTC
    File::Find actually sounds ideal for what you want, and it will most likely do it better than you could yourself. Typical file-tree depth searchers get hung up on symbolic links if you don't explicitly take them into account. File::Find will handle this and other problems with aplomb. It's also very flexible; just plug in your matching function (wanted() in the docs) and you're up and running. See Corion's review and following thread for additional considerations, and the local copy of the |File::Find doc for how to use it. And of course, there are a boatload of existing nodes around the site (see above posts) relating to the module.
Re: traversing directory's
by aardvark (Pilgrim) on Mar 12, 2001 at 01:21 UTC
    You may want to look here or here or here for starters.

    Get Strong Together!!

Re: traversing directory's
by Chady (Priest) on Mar 12, 2001 at 01:22 UTC