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

I have alot of files in my web root directory that I need to change data in AND I have two direcotories out of 30 in this web root directory that I need to change data in. The File::Find works great in the two directories I need to change data in but not sure how I can change the files located in web root. Please advise how I can correct this File::Find so it will search and replace in my web root and do the recursive search in the two directories (called AA and BB).

Here is my search part where I tried several ways:
#Does the search in AA and BB only and doesnt touch my web root files find( \&subsearch, map "$dirs/$_", qw( AA BB ));
#Does the search in ALL 30 of my directories and does search my web ro +ot find( \&subsearch, map "$dirs/$_", qw( . AA BB ));
#Same thing where it seaches all 30 of my directories and web root fil +es find( \&subsearch, map "$dirs/$_", qw( ./ AA BB ));

Replies are listed 'Best First'.
Re: Search criteria
by Zaxo (Archbishop) on Aug 01, 2003 at 14:33 UTC

    You could use a 'preprocess' routine to filter out the unwanted directories. Untested code,

    find( { wanted => \&subsearch, preprocess => sub { grep { -f || -d _ && /^AA|BB$/ } @_ } }, $dir );

    After Compline,
    Zaxo

      Is the preprocess rountine dependent on Perl version? I have Perl 5.005 version.

        AFAIK, it should work for 5.005. I warned the code was untested, what I wrote is based on how I think it should work. You may need to play with it a bit to tune it up. Check your version of File::Find, too.

        After Compline,
        Zaxo

Re: Search criteria
by dragonchild (Archbishop) on Aug 01, 2003 at 14:18 UTC
    You might have to do two finds. That's not a bad thing.

    ------
    We are the carpenters and bricklayers of the Information Age.

    The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6

    Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.