[VPM] Perl threads recursion
Jeremy Aiyadurai
jeremygwa at hotmail.com
Wed May 7 19:47:58 CDT 2003
hi all,
I have the following problem, involving recursion and threads. i have a
recursive subroutine that scans a directory structure from a given root, and
performs operations on files it finds which meet a certain criteria. I find,
that running this in a single thread is rather time consuming, especially
when there are alot of files to process and directories to go through.
I want a new thread created for each recursive call to the subroutine. The
subroutine is called when a sub directory is found. I am not an expert on
threads or forks in perl, and have had alot of errors, when trying to apply
them. I am using perl 5.8 from Activestate. My OS is Windows 2000 Pro.
Your help is much appreciated.
thanks in advance,
Jeremy A.
P.S: below this line is the recursive subroutine.
------------------------------------------------------------------------------
sub rgrab ($$) {
my $current = $_[0];
my $path = "$_[1]/$current";
mkdir($current);
chdir($current);
opendir(DDD,".");
my @files = readdir(DDD);
foreach (@files) {
if (-f $_) # if a file
{
if($_ =~ /filenamehere/ig)
{
# do stuff to file here
}
}
elsif(-d $_) #if a directory
{
#print "$_\n";
if (($_ ne ".") && ($_ ne ".."))
{
print "changing to directory:$_\n";
&rgrab( $_, $path );
chdir("..");
}
}
}
closedir(DDD);
}
_________________________________________________________________
The new MSN 8: advanced junk mail protection and 2 months FREE*
http://join.msn.com/?page=features/junkmail
More information about the Victoria-pm
mailing list