Greetings all,

Update: After flushing out the code to a full working example as per AnonomousMonk's remark, the problem does not reproduce.

I have to get back to my original code and find the error now that I have a working example.

The original question, updated to fit the updated (and working) code:

Here is my setup for parallel processing of arrays and hashes:

#!/usr/bin/env perl use strict; use warnings; use 5.30.0; use utf8; use utf8::all; use Data::Dump 'pp'; use Parallel::ForkManager; my $pal = new Parallel::ForkManager(6, '/tmp/' ); my @array = (3..56); my $array_ref = \@array; my %results; sub one { ### seting up parallel processing for six processors. my %data; my $data_ref = \%data; my $sixes = sub { my $input = shift; my $leng = int( $input / 6) + 1; my %ha; foreach (0..5) { $ha{"$_"}{'a'} = $_ * $leng; $ha{"$_"}{'b'} = ( $_ + 1 ) * $leng - 1; } $ha{"5"}{'b'} = $input; return sub { my ( $body, $finish) = @_; $pal->run_on_finish( sub { &$finish } ); foreach (0..5) { $pal->start and next; foreach ( $ha{"$_"}{'a'}..$ha{"$_"}{'b'} ) { &$body; } $pal->finish(0, \%results); } $pal->wait_all_children; } }; ## I arm (set,prime?) the closure thus: $$data_ref{'fork_s'} = $sixes->( $#$array_ref ); two($data_ref); } sub two { my $data_ref = shift; $$data_ref{'fork_s'}->( sub { my $sn = "$_"; ## = number of sentence $results{'SxW'}{"$sn"}++; # say "Results: ".pp(%results); }, sub { my $refe = $_[5]; say "Refe2 empty" if !defined $refe; if (defined($refe)) { say "Refe2 " . pp($$refe{'SxW'}); } }); } one()

The set up serves to have a routine for processing data from an array in parallel.

Testing with the exact same call from within one() worked, while in two() the data was processed correctly but did not show up in the run_on_finish section.

As stated above, now it works, so I have to go back to my code and find its problem, but confidently.

I had thought that the passing of the sub reference was playing up with Paralell::ForkManager.

Regards,

In reply to [solved] Passing a sub reference which uses Parallel::ForkManager by minor_wazoo

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.