G'day micmac,

If you add use warnings;, you'll see that the exec is not being run at all:

$ pm_child_execs.pl in test2 Can't exec "1": No such file or directory at ./pm_child_execs.pl line +13. in test1 Can't exec "1": No such file or directory at ./pm_child_execs.pl line +13. in test2 Can't exec "1": No such file or directory at ./pm_child_execs.pl line +13.

What's actually happening is that $cmd->() is being run then exec is trying to use the return value ("1" from say) as its argument.

So, the first child runs test1() then, because there's no exec, it runs test2() on the second iteration. The second child runs test2() (also with no exec). That's test1() once and test2() twice.

Changing

exec $cmd->();

to

#exec $cmd->(); $cmd->(); last;

you'll get the desired output:

$ pm_child_execs.pl in test2 in test1

I'll leave you to decide if that's also the desired functionality.

-- Ken


In reply to Re: parallel functions by kcott
in thread parallel functions by micmac

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.