2013-06-26 75 views
0

我想對線程編程perl的以下列方法來調用從另一個Perl模塊,子程序:如何使用線程

Description: 目前的perl腳本需要調用其它子程序的另一種Perl模塊,在存在(名.pm文件)使用線程方法。使用線程callign子程序

Case1:一般的方法是像

my $t= Thread->new(\&process, @args); 

其中處理是子程序在同一perl的文件是否存在。

Case2:調用它存在一個不同的perl模塊

my $t= Thread->new(\&$anotherfile->another_process, @args); 

其中不同的perl模塊中存在another_process和不在同一perl的文件中的子程序。

問題是Case2不適合我。我無法將任何參數傳遞給此線程。 任何人都可以幫助解決這個問題嗎?

+1

首先,你應該'use'或'require'包從另一個文件,並通過包指向它的方法。你的'線程'是舊的和不贊成的線程模型;你正在使用哪個perl版本? –

回答

0

因爲情況2給螺紋從varibale anotherfile方法another_process回報的參考...

嘗試使用封閉:

threads->create(
    sub { 
     return $anotherfile->another_process(@_); 
    }, 
    @args 
);