It is an actual data structure reference. I have this in some of my code somewhere:

$pm->run_on_finish( sub { $buckets->{$_[0]} = $_[1] for @{$_[5]}; } );

So that means that $_[5] ($data_structure_reference) is shaped something like:

$data_structure_reference = [ ['a', 1], ['e', 1], ['l', 1], ['p', 2], ]

Keep in mind the following information from the POD for Parallel::ForkManager:

The ability for the parent to retrieve data structures is new as of version 0.7.6.

Each child process may optionally send 1 data structure back to the parent. By data structure, we mean a reference to a string, hash or array. The contents of the data structure are written out to temporary files on disc using the Storable modules' store() method. The reference is then retrieved from within the code you send to the run_on_finish callback.

The data structure can be any scalar perl data structure which makes sense: string, numeric value or a reference to an array, hash or object.

There are 2 steps involved in retrieving data structures:

1) A reference to the data structure the child wishes to send back to the parent is provided as the second argument to the finish() call. It is up to the child to decide whether or not to send anything back to the parent.

2) The data structure reference is retrieved using the callback provided in the run_on_finish() method.

Keep in mind that data structure retrieval is not the same as returning a data structure from a method call. That is not what actually occurs. The data structure referenced in a given child process is serialized and written out to a file by Storable. The file is subsequently read back into memory and a new data structure belonging to the parent process is created. Please consider the performance penalty it can imply, so try to keep the returned structure small.

In the case of my code example, the data structure is being layered into a hash that has been in scope since before the forked children were created.


Dave


In reply to Re: Parallel:ForkManager how to pass back a list by davido
in thread Parallel:ForkManager how to pass back a list by cormanaz

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.