submersible_toaster has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks

While fiddling around with 5.8.0 and threads I found problems getting the correct return from my threads using ->join Returning a scalar seems to be no problem but trying to return an array or hash seem to be evaluated in scalar context.

#!/usr/dev/perl/bin/perl -w use strict; use threads; use Data::Dumper; my $thread = threads->new( sub { my %foo; @foo{1..100} = (1..100); print Dumper %foo; return %foo } ); print "Upon Joining ", $thread->join;

Replies are listed 'Best First'.
Re: threads->join Return Context.
by submersible_toaster (Chaplain) on Nov 19, 2002 at 06:48 UTC
    Gahhh.. Not really a question is it?!
    Not to mention that I just realised that returning a reference works no worries... but what if I wanted to return an array and a hash... push references to each into an array and return a reference to that? Aye.
Re: threads->join Return Context.
by Aristotle (Chancellor) on Nov 20, 2002 at 15:25 UTC
    return [ \%foo, \@bar, $baz ]; or maybe
    return { foo => \%foo, bar => \@bar, baz => $baz, };

    Makeshifts last the longest.