Maybe you could post the error to the list?

The problem may be the version of Perl you are using.  Stable threads were
introduced in version 5.8.  In 5.6 they are experimental (maybe part of the
problem?) and use a different syntax.

You seem to be using "use thread" which is the 5.8 syntax, but 5.6 uses use
"Thread".

I suggest upgrading if you can.

Rob

-----Original Message-----
From: Sharmarke Aden [mailto:[EMAIL PROTECTED]
Sent: Friday, March 14, 2003 2:56 PM
To: '[EMAIL PROTECTED]'
Subject: Help with Threads.


I'm new to Perl and trying to access several directories at the same time
and simply read the content of the directory and do some processing on the
files in those directories. The code below is a reference code to get
started on the real work. The code below however crashes and I'm lost as to
what the cause is. Any help you could give me I'd appreciate it. This code
simple in that it looks for 3 letter directories and creates a stats file
used to report the files in that directory. Eventually what I'll want to do
is run those files through processing and take advantage of a bitching 8
processor machine we just got. BTW I'm using Perl 5.6 on win 2000 machine
(ActivePerl-5.6.0.623-MSWin32-x86-multi-thread to be exact).

 

#code starts

 

use threads; 

 

$currDir = `cd`;
chop($currDir);
opendir(IP_MAIN_DIR, $currDir);

 

#remove '.' and '..'

@allBatchFolders = grep !/^\.\.?$/, readdir IP_MAIN_DIR;
#get the names of all the 3 character directories in to a list/array ("aaa"
and "aab, and "aac" qualify)

@allBatchFolders = grep /^[a-z][a-z][a-z]$/, @allBatchFolders;

 

#open stat file for writing
open(STATFILE, ">$currDir\\stat.txt");
$index = 0;

foreach $aDir (@allBatchFolders)
{
  $aThread[$index] = threads->new(\&writeStat, $aDir);
 @ReturnData = $aThread[$index]->join();
 $index++;
}

closedir(IP_MAIN_DIR);
close(STATFILE);

 

sub writeStat
{
  $localDir = $currDir . "\\" . $_[0];
  local *DIRECTORY;
  opendir(DIRECTORY, $localDir);
  print "Start wile loop: @_[0]\n";
  print STATFILE "Start wile loop: @_[0]\n";
  rewinddir( DIRECTORY );
  while ($file = readdir(DIRECTORY))
  {
    writeToFile(@_[0], $file);   
  }
  print STATFILE "End wile loop: @_[0]\n";
  print "End wile loop: @_[0]\n";
  closedir(DIRECTORY);
}

 

sub writeToFile 

{

    use attrs qw(locked); 
    print STATFILE "Thread @_[0]: @_[1]\n";
}

 

#code ends

 

 

 

----------------------------------------------------------------

Sharmarke Aden

Continental DataGraphics [www.cdgpd.com <http://www.cdgpd.com> ]

Direct: (425) 691-2583

Fax: (425) 450-1935

Email: [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> 

----------------------------------------------------------------

 


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

Reply via email to