I am trying to get one of the examples from the official documentation working. I accept that putting code snippets together has problems, but I have tried lots of variants without success. The example is about 75% of the way through the document and starts with my $pool = AnyEvent::Fork. My current version of it is:

use strict; use warnings; use AnyEvent; use AnyEvent::Fork; use feature 'say'; package Some; # Some::function might look like this - all parameters passed before f +ork # and after will be passed, in order, after the communications socket. sub funct{ my ($fh, $str1, $str2, $fh1, $fh2, $str3) = @_; print scalar <$fh>; # prints "hi #1\n" and "hi #2\n" in any order } package main; my $pool = AnyEvent::Fork ->new ->send_arg ("str1", "str2") ; for (1..2) { $pool ->fork ->send_arg ("str3") ->run ("Some::funct", sub { say 'Inside anonysub'; }); } say 'Outside pool loop'; AnyEvent->condvar->recv;

Thjis goes into an infinite loop after printing the output below:

Outside pool loop Inside anonysub Inside anonysub Goto undefined subroutine &Some::funct at /usr/local/share/perl/5.24.1 +/AnyEvent/Fork/Serve.pm line 87. Goto undefined subroutine &Some::funct at /usr/local/share/perl/5.24.1 +/AnyEvent/Fork/Serve.pm line 87.

I'm not worried about the infinite loop - at least not yet - but the inability to find a fully qualified sub (what the docs say is required) puzzles me. Could someone please give me a pointer?

Regards,

John Davies


In reply to AnyEvent::Fork not working as expected by davies

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.