0

I am trying for thread programming perl in a following way:

Description: The current perl script needs to call another subroutine exists in the another perl module(.pm file) using thread method.

Case1: general way of callign subroutine using threads is like

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

where process is the subroutine exists in the same perl file.

Case2: calling the subroutine which exists in a different perl module

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

where another_process exists in the different perl module and not in the same perl file.

Question is that Case2 is not working for me. I am not able pass any arguments to this thread. Can any one helpme to solve this issue?

4

1 回答 1

0

因为案例 2 给出了从变量 anotherfile 上的方法 another_process 返回的线程引用...

尝试使用闭包:

threads->create(
    sub {
        return $anotherfile->another_process(@_);
    },
    @args
);
于 2013-06-26T12:43:43.747 回答