I want to try program on process. As monks suggested I am using Parallel::ForkManager. As per module document I tried this code.

#!/usr/bin/perl use warnings; use strict; use Benchmark; my $t0 = Benchmark->new; use Parallel::ForkManager; my @links=("ALPHA","Numeric"); # Max 30 processes for parallel download my $pm = Parallel::ForkManager->new(2); sub alpha { foreach my $i (900 .. 1900) { print 'A',"\t"; } } sub numeric { foreach my $j (1 .. 1000) { print $j,"\t"; } } LINKS: foreach my $linkarray (@links) { $pm->start and next LINKS; # do the fork if ($linkarray eq "ALPHA") { alpha(); } if ($linkarray eq "Numeric") { numeric(); } $pm->finish; # do the exit in the child process } $pm->wait_all_children; my $t1 = Benchmark->new; my $td = timediff($t1, $t0); print "the code took:",timestr($td),"\n";

But the output is not like what I expected. Its printing A thousand time and after 1..1000 and again A's 1000 times and again 1..1000. What I expected is if the process running parallel A's 50 (suppose) and then 1..50 and again A and again numeric's like this. I am doing anything wrong????

Update

Small minor change in code


In reply to Odd behaviour of Parallel::ForkManager by ravi45722

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.