for more info: perldoc File::Find

within your "wanted" sub the default variable $_ is set to the name of the
current filename within the current directory.

$File::Find::dir gives you the path of the current directory
$File::Find::name gives you the full path to the current file

(there are some others too, like $File::Find::topdir, topdev, topino,
topmode, and toplink)

SO
        push(@files,$File::Find::name) if(/$ending$/i);


looks at the current filename ($_) and sees if it matches $ending at the end
of it... 
so if $ending eq "txt" it will match filenames that end with "txt" and be
case insensitive (/txt$/i)  

if it does match that regular expression, then it pushes the FULL path
($File::Find::name) onto our list of found files (@files)  so that we can
read from that list later if we want.

If you're only interested in printing the files that match once when you
find them, then just use

        print "$File::Find::name\n" if(/^nameOfFile$/i);

or something similar...  Then,if you want, you could pipe the output of this
script to a text file or some other command to deal with your list of found
files....

Hope this makes sense.  Read up on File::Find for more info.

cheers

-peter

-----Original Message-----
From: Lile, James AZ2 (VAW-115) [mailto:[EMAIL PROTECTED]

hello,
Quick question,
what does this line do?
        push(@files,$File::Find::name) if (/$ending$/i);
I wrote a simalor script to find a certain file on my computer and the only
way I got it to work was by using this code in my WANTED sub
 if ( File::Find::name eq File::Find::dir/$file ) {
        print "matches..."
        }
that isn't the exact way it way written...
does the pushing of the array of @files do the same thing?
thanks for you time,
James Lile


-----Original Message-----
From: Peter Kappus [mailto:[EMAIL PROTECTED]

#!/usr/bin/perl -w
use File::Find;
use strict;
use warnings;           #HEY!  Do i need this with -w?  somebody tell me...

my $root = "C:/temp";   #directory to start from
my $ending = ".pbd";    #extension to search for 
my @files;              #our list of found files

#go look for it...
#pass our subroutine for processing each file and the root dir
find(\&gotIt, $root);  

#print our list all pretty like, with linebreaks
print join("\n",@files);

sub gotIt{
                push(@files,$File::Find::name) if (/$ending$/i);
}

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to