Re: Perl threads - capturing value returned from sub



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
.



Relevant Pages

  • Record Validation Strategy
    ... I would like to provide an exit button, ... I could Cancel, but I get an unwanted "Close Action cancelled" message. ... For Each ctl In Me.Controls ... exit sub ...
    (microsoft.public.access.forms)
  • Re: Record Validation Strategy
    ... Private Sub cmdExit_Click ... I would like to provide an exit button, ... I could Cancel, but I get an unwanted "Close Action cancelled" message. ... Dim intResponse As Integer ...
    (microsoft.public.access.forms)
  • Re: stop code sending cancelled email
    ... close the email without sending The cancel triggers error ... "Alex Dybenko" wrote: ... Private Sub Command5_Click ... Exit Sub ...
    (microsoft.public.access.modulesdaovba)
  • Re: Cancel Form and Hopelessly Lost Again
    ... All that setting the Cancel property on the button really does is make ... True cancels the event (stops the user leaving the textbox, ... tidy up events occur - in your case, the textbox exit and, perhaps, others. ... anyway) because the textbox is in a Frame. ...
    (microsoft.public.word.vba.userforms)
  • RE: User Saving a Record else it deletes
    ... before update command which only runs when the user scrolls to another record ... or tries to exit. ... > Make a Cancel button on the form, ... > End Sub ...
    (microsoft.public.access.forms)