Re: Perl threads - capturing value returned from sub
- From: "Eric" <ecarlson@xxxxxxxxxx>
- Date: 27 Feb 2007 08:12:38 -0800
On Feb 27, 7:21 am, zentara <zent...@xxxxxxxxxxxxxx> wrote:
On 26 Feb 2007 17:24:40 -0800, "Eric" <ecarl...@xxxxxxxxxx> wrote:
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
Just to amplify slightly, you can return arrays too.
#!/usr/bin/perl
use warnings;
use strict;
use threads;
use threads::shared;
# join() does three things: it waits for a thread to exit,
# cleans up after it, and returns any data the thread may
# have produced.
my $thr = threads->new(\&sub1);
my $return = $thr->join;
print "Thread returned @$return\n";
#hold for key input
<>;
##########################################################
sub sub1 {
my @values = ('1',2, 'ten');
print "@values\n";
while(1){sleep 1}
return \@values;
}
__END__
--
I'm not really a human, but I play one on earth.http://zentara.net/japh.html
Thanks - this is useful information.
Eric
.
- References:
- Perl threads - capturing value returned from sub
- From: Eric
- Re: Perl threads - capturing value returned from sub
- From: Eric
- Re: Perl threads - capturing value returned from sub
- From: zentara
- Perl threads - capturing value returned from sub
- Prev by Date: Re: DocumentHTML ?
- Next by Date: Disable warnings from specific module
- 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
|