Re: Perl threads - capturing value returned from sub
- From: "Eric" <ecarlson@xxxxxxxxxx>
- Date: 26 Feb 2007 17:24:40 -0800
On Feb 26, 5:03 pm, "Eric" <ecarl...@xxxxxxxxxx> wrote:
Hello,
I am using Perl threads to launch multiple executions of a command in
parallel. The code to do this is:
foreach my $Machine ($self->Machines) {
my $thr = threads->new(\&doPowerAction, $Machine);
}
foreach my $t (threads->list()) {
$t->join;
}
The sub referenced is:
sub doPowerAction
{
my $machine = shift;
my $runScript = `power.exp $machine`;
if ($runScript =~ m/SUCCESS/) {
return "SUCCESS";
} elsif ($runScript =~ m/FAILURE/) {
return "FAILURE";
} else {
return "INTERNAL_ERROR";
}
}
The problem is that I don't seem to be able to figure out how to
capture the return value in the calling routine. Does anyone know how
to do this?
Thanks in advance to all that respond.
Eric
Cancel this one; I found the answer, which was to just assign a
variable to the join:
my $result = $t->join;
Seems like I always have a breakthrough immediately after I post to
this site! :)
Eric
.
- Follow-Ups:
- Re: Perl threads - capturing value returned from sub
- From: anno4000
- Re: Perl threads - capturing value returned from sub
- From: zentara
- Re: Perl threads - capturing value returned from sub
- References:
- Prev by Date: Re: Perl threads - capturing value returned from sub
- Next by Date: Re: Perl threads - capturing value returned from sub
- Previous by thread: Re: Perl threads - capturing value returned from sub
- Next by thread: Re: Perl threads - capturing value returned from sub
- Index(es):
Relevant Pages
|