in reply to Re^2: perlcritic and MCE::Loop
in thread perlcritic and MCE::Loop

did you separate the arguments behind the block with a comma after introducing "sub"?

DB<25> sub run (&@) { my $code =shift; $code->(@_) } DB<26> *mce_loop = \&run DB<27> mce_loop {print "code @_"} 1,2,3 # no comma needed code 1 2 3 DB<28> mce_loop sub {print "code @_"}, 1,2,3 # comma needed code 1 2 3 DB<29> mce_loop sub {print "code @_"} 1,2,3 # syntax error Number found where operator expected at (eval 38) ...

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

Replies are listed 'Best First'.
Re^4: perlcritic and MCE::Loop
by redtux (Sexton) on Feb 20, 2021 at 14:52 UTC
    Thanks, I missed that, working now

    My previous "solution" didn't work, code ran but mce_loop did nothing.

    All seems to be working now and perlcritic happy

      > My previous "solution" didn't work, code ran but mce_loop did nothing.

      That's obvious.

      Defining an anonymous sub won't execute it but return the code-ref.

      DB<39> p sub { print "run @_" } # returns ref CODE(0x2e80a90) DB<40> sub{ print "run @_" }->(1..3) # calls ref run 1 2 3 DB<41>

      Though I'm a bit surprised, my muscle memory wanted brackets around the ref for precedence:

      ( sub{ print "run @_" } )->(@_)

      this could still be needed in other contexts. (or - more likely - it's just cargo cult from JS ;)

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery

      > and perlcritic happy

      Still strange, there is a bug somewhere in this policy.

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery