Chinaunix首页 | 论坛 | 博客
  • 博客访问: 144186
  • 博文数量: 47
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 402
  • 用 户 组: 普通用户
  • 注册时间: 2013-03-11 10:08
文章存档

2013年(47)

我的朋友

分类: PERL

2013-04-25 18:10:41

sub doWork
{
   my $files=shift;
   for my $file (@$files)
   {
      #deal with file.
   }
}
 
sub getFiles
{
   #read files from dir and 
   #you can dispatch the files into a number of arrays
   #these you should pass into subprocesses.
}
 
sub main
{
   my @arrayofarray=getFiles($n);#$n can be the number of subprocs.
   foreach my $files (@arrayofarray)#$files is a reference to array.
   {
      my $pid=fork();
      if($pid==0)
      {
         return doWork($files);
      }
   }
   wait(-1);#wait for all subprocesses.
}

阅读(865) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~