Qustion about ithreads join

T

Taewoon Kwon

Nowadays, I learn about perl ithreads, reading perlthrtut perldoc.

I tested a sample code in that document

#---code start
use threads;

$thr = threads->new(\&sub1);

@ReturnData = $thr->join;
print "Thread returned @ReturnData";

sub sub1 { return "Fifty-six", "foo", 2; }
#---code end
and result of above code was printing '2', not 'Fifty-six foo 2'.

As far as I know it should print the 'Fifty-six foo 2'.
Could somebody explain the result?

Platform I tested the code was ActiveState Perl v5.8.4 for windows, and
perl v5.8.1 built in Mac Os X. Both showed the same result.
 
J

Joe Smith

Taewoon said:
sub sub1 { return "Fifty-six", "foo", 2; }
#---code end
and result of above code was printing '2', not 'Fifty-six foo 2'.

As far as I know it should print the 'Fifty-six foo 2'.
Could somebody explain the result?

@array = sub1();
print "In list context, the result is @array\n";
$scalar = sub1();
print "In scalar context, the result is $scalar\n";

You should not expect them to return the same results.
-Joe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top