davies has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: AnyEvent::Fork not working as expected
by jo37 (Curate) on Jun 28, 2021 at 20:12 UTC | |
|
Re: AnyEvent::Fork not working as expected
by Aldebaran (Curate) on Jul 01, 2021 at 06:07 UTC | |
by choroba (Cardinal) on Jul 01, 2021 at 10:34 UTC |