Wanted is where you want to change this.  Within the function place a
regular expression or file-test ...anything that will give you a true/false
answer that you can use.

To get a list of executable files you would change

>sub wanted {
>          print "$File::Find::name\n";
>}

to:

sub wanted {
     if ( -x "$File::Find::name" )
     {
           print "$File::Find::name\n";
     }
}
This test the filename passed and prints out the result.  You can change
the print statement to add the filename to a array or hash, or perform and
open on the file, whatever you want.

For your case this should work:
_boot.js

<snip>
my (@FILES);
<snip>
sub wanted {
     if ( $File::Find::name =~ /_boot\.js$/ )
     {
           push @FILES, "$File::Find::name";
     }
}

This will add any filename that ends with _boot.js to the array FILES.
When declaring the FILES array do not use:
@FILES = "";
This will place a blank line within your array and may cause problems later
(massive problems for me :).

Have fun,


-----------------------------------------
Craig Moynes
Internship Student
netCC Development
IBM Global Services, Canada
Tel: (905) 316-3486
[EMAIL PROTECTED]



                                                                                       
                            
                    "Kaustav                                                           
                            
                    Bhattacharya"        To:     <[EMAIL PROTECTED]>                  
                            
                    <kaustav@kaust       cc:                                           
                            
                    av.uk.com>           Subject:     traversing dir tree and reading 
in files                     
                                                                                       
                            
                    05/01/01 10:39                                                     
                            
                    AM                                                                 
                            
                    Please respond                                                     
                            
                    to kaustav                                                         
                            
                                                                                       
                            
                                                                                       
                            



been trying to work out how to get PERL to traverse a given directory tree
looking for all files with the string _boot.js in the file name. then I
want
to read each file and find all lines which start with the string "sWinReg"
and copy them in to an array with each line being places in a seperate cell
in the array.  So far I have written some code to run down the directory
tree which looks like this:

use File::Find;
find(\&wanted, 'D:\\app\\pages\\services\');

sub wanted {
           print "$File::Find::name\n";
}

this lists all the files in the given path, but I can't work out how to
list
only files which contain "_boot.js" in the file name. I only want those
files and none of the others.and how would I put each line outputted in to
an array? Do a "foreach" and "push" each item in to the array as it's read
in from the FS?

Any pointers on how to do this?

Kaustav
--
Kaustav Bhattacharya
[EMAIL PROTECTED]
Mobile: +44 (0)771 421 6919





Reply via email to