Dear Masters,

I have a code that takes values from the initially generated hash and array from some functions. In the un-threaded situation my code looks like this:
use strict; use warnings; my @array1 = funct_array($par1,$par2,$filename); my %hash1 = funct_hash($par1,$par2,$par3,$filename); # there are more tables/lists like this # then followed process that # takes the pre-generated value from @array1 and %hash1. # Thus both @array1 and %hash1 must be completed first. # Subroutine list sub funct_array { my ($p1,$p2,$fn) = @_; my @array_result; # Run some time consuming process return @array_resutlt; } sub funct_hash{ my ($p1,$p2,$fn) = @_; my %hash_result; # Run some time consuming process return %hash_resutlt; }

Then to speedup the process, I am trying to use thread. Here is what I did:
use strict; use warnings; use threads; use Data::Dumper; my $array1 = threads->new(\&funct_array,($par1,$par2,$filename)); my $hash1 = threads->new(\&funct_hash,($par1,$par2,$par3,$filename)); # Then I tried to see the content of the array # with Data Dumper print Dumper $array->join; print Dumper $hash1->join; # But I couldn't see any value of @array1 and # %hash1 that I can use for the later process # Subroutine list sub funct_array { my ($p1,$p2,$fn) = @_; my @array_result; # Run some time consuming process return @array_resutlt; } sub funct_hash{ my ($p1,$p2,$fn) = @_; my %hash_result; # Run some time consuming process return \%hash_resutlt; }
As I stated in my snippet above, I couldn't recover back the returned value of array and hash after threading. What's wrong with my code?

---
neversaint and everlastingly indebted.......

In reply to Howto capture array/hash back after threaded process by neversaint

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.