Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6111873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:40:50+00:00 2026-05-23T14:40:50+00:00

I want to have children processes write to the parent’s @array. I’ve read about

  • 0

I want to have children processes write to the parent’s @array. I’ve read about piping but I’m very confused on how to actually implement it:

use Parallel::ForkManager;
my @array;
my $pm=new Parallel::ForkManager(3); 

    for((1..5)){
    $pm->start and next; 
    print "child: ".$_."\n";
    push(@array,$_); # what do I do here to put it into the parent's @array????
    $pm->finish; 
    }
$pm->wait_all_children;


print "parent: ".$_."\n" for @array;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:40:50+00:00Added an answer on May 23, 2026 at 2:40 pm

    If you want to use pipes, then you need to create a pair of pipes before you spawn each child, write to the writing pipe from the child, and use IO::Select to read from all of the reading ends in parallel in the parent. You’ll also need to change the way you wait for the children, since ForkManager’s wait_all_children is blocking, which isn’t very useful. You could use a run_on_start method to register each process in a hash and a run_on_finish method to delete each process after it dies, and then terminate the select loop when no processes are remaining.

    Or, if it’s not important that the children can pass their results back to the parent in realtime, you can use ForkManager’s ability to pass data back to the parent on exit through the finish call, which would look something like:

    #!perl
    use strict;
    use warnings;
    use Parallel::ForkManager;
    
    # No indirect object notation
    my $pm = Parallel::ForkManager->new(3);
    my @array;
    $pm->run_on_finish(sub {
        my $return = $_[5]; # Count 'em.
        push @array, @$return;
    });
    
    for(1..5) {
      $pm->start and next;
      print "child: $_\n";
      $pm->finish(0, [$_]);
    }
    
    $pm->wait_all_children;
    
    print "parent: $_\n" for @array;
    

    which actually works.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assuming I have the following html div which I want to replicate its children,
I have a typical nested tree model and I want to build an array
I am doing a children's book using Leaves. I want to have a different
I am trying to figure out children processes of a given parent from ps
i want have an image and i want to set it as a background
want to have a Hyperlink-Button in a gridView in which I can display a
I want to have a select-only ComboBox that provides a list of items for
I want to have a text box that the user can type in that
I want to have a PHP script send a XML formatted string to another
I want to have a class which implements an interface, which specifies the specific

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.