Unless the OP edited the code, his example does not have a closure. He alluded to tracking the exit codes via a HASH but that sounded more like a global than a closure. I believe the OP may be looking for someway to update his database inside the run_on_finish command -- in that case he could just close over the database handle instead of some data structure which could be manipulated *after* the run of all the children.

Update: ... forgot an (untested) example:

my $dbh = create_dbh_handle(); my $code = create_closure( $dbh ); .... my $pm = Parallel::ForkManager->new( $MAX_NR_PROCESSES ); $pm->run_on_finish( $code ); foreach ... { my $pid = $pm->start and next; ... $pm->finish; # Terminates the child process } sub create_closure { my( $dbh ) = @_; return sub { my ($pid, $exit_code, $ident) = @_; my $sql = "insert into table values( $pid, $exit_code )"; $dbh->do( $sql ); } }

-derby

In reply to Re^3: Parallel::ForkManager run_on_finish exit code handler by derby
in thread Parallel::ForkManager run_on_finish exit code handler by sojourn548

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.