Multithreading Perl线程-从模块(pm)调用子例程
启动额外perl模块中定义的子例程线程的正确语法是什么 perl程序:Multithreading Perl线程-从模块(pm)调用子例程,multithreading,perl,Multithreading,Perl,启动额外perl模块中定义的子例程线程的正确语法是什么 perl程序: use strict; use warnings; use forks; require testModule; # before solution - thanks ysth! # testModule->main will not work! #my $thr1 = threads->new(\&testModule->main, "inputA_1", "inputB_1"); #my $t
use strict;
use warnings;
use forks;
require testModule;
# before solution - thanks ysth!
# testModule->main will not work!
#my $thr1 = threads->new(\&testModule->main, "inputA_1", "inputB_1");
#my $thr2 = threads->new(\&testModule->main, "inputA_2", "inputB_2");
# solved
#my $thr1 = threads->new(\&testModule::main, "inputA_1", "inputB_1");
#my $thr2 = threads->new(\&testModule::main, "inputA_2", "inputB_2");
my @output1 = $thr1->join;
my @output2 = $thr2->join;
perl模块testModule.pm:
package testModule;
sub main{
my @input = @_;
#some code
return ($output1, $output2)
}
testModule->main的确切系统调用是什么
提前谢谢 你几乎做对了:
...threads->new( \&testModule::main, "inputA_1", "inputB_1" );
->
仅用于类/实例方法调用;如果希望将其作为类方法调用(这将使@input
获得类名以及“inputA_1”和“inputB_1”),则可以执行以下操作:
...threads->new( sub { testModule->main(@_) }, "inputA_1", "inputB_1" );
谢谢,这很简单;)我在perl代码中添加了解决方案-谢谢你!