Re: Perl threads - capturing value returned from sub
- From: zentara <zentara@xxxxxxxxxxxxxx>
- Date: Tue, 27 Feb 2007 10:21:06 -0500
On 26 Feb 2007 17:24:40 -0800, "Eric" <ecarlson@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
.
- Follow-Ups:
- References:
- Prev by Date: FAQ 5.31 How do I do a "tail -f" in perl?
- Next by Date: LWP:Authen:NTLM
- 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
|