Is there a way to run parallel forks without using a loop or using Parallel::Fork::BossWorker? So I tried just using fork(), but that doesn't allow running forks in parallel. Next was Parallel::ForkManager, which wouldn't allow me to fork unless I was inside a loop of some sort. Maybe I'm missing something but I don't see the importance of having this as an arbitrary limitation. Last I tried Parallel::Fork::BossWorker which worked but doesn't seem to allow me to fork a subroutine and store the return values in a variable. I just want to fork the subroutines and store the return values in a hash. Here's a simplified example of my code.

#!/usr/bin/perl use strict; use warnings; no warnings "uninitialized"; use Parallel::Fork::BossWorker my $data = "a"; my $fork_sub1 = Parallel::Fork::BossWorker->new(work_handler => \&sub1 +); my $fork_sub2 = Parallel::Fork::BossWorker->new(work_handler => \&sub2 +); my $fork_sub3 = Parallel::Fork::BossWorker->new(work_handler => \&sub3 +); my $fork_sub4 = Parallel::Fork::BossWorker->new(work_handler => \&sub4 +); my $fork_sub5 = Parallel::Fork::BossWorker->new(work_handler => \&sub5 +); my $fork_sub6 = Parallel::Fork::BossWorker->new(work_handler => \&sub6 +); $fork_sub1->add_work({data => "a"}); $fork_sub2->add_work({data => "a"}); $fork_sub3->add_work({data => "a"}); $fork_sub4->add_work({data => "a"}); $fork_sub5->add_work({data => "a"}); $fork_sub6->add_work({data => "a"}); $fork_sub1->process(); $fork_sub2->process(); $fork_sub3->process(); $fork_sub4->process(); $fork_sub5->process(); $fork_sub6->process(); sub sub1 { my $variable = shift @_; print "sub 1\n"; return(0); } sub sub2 { my $variable = shift @_; print "sub 2\n"; return(0); } sub sub3 { my $variable = shift @_; print "sub 3\n"; return(0); } sub sub4 { my $variable = shift @_; print "sub 4\n"; return(0); } sub sub5 { my $variable = shift @_; print "sub 5\n"; return(0); } sub sub6 { my $variable = shift @_; print "sub 6\n"; return(0); }


In reply to parallel forks by networker2149

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.