in reply to perlcritic and MCE::Loop

> Any ideas?

Short guess: write

%result = mce_loop sub {

if you want to keep that Citric rule activated.

Long guess: mce_loop seems to be defined with a prototype (&) which treats a following code block like a sub

Critic doesn't see that and thinks the @_ is not at the right position.

Inserting an explicit sub should fix that

Disclaimer: I'm neither a user of critic nor mce, and can't test.

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

update

It's unlikely that Critic is always doing that, because such prototype stuff is not uncommon. The full answer is in your environnement.

Replies are listed 'Best First'.
Re^2: perlcritic and MCE::Loop
by redtux (Sexton) on Feb 19, 2021 at 19:07 UTC
    For info doing this

    %result = mce_loop sub {

    Results in a syntax error

    However wrapping the the whole thing in a sub removes the error, will have to see if it breaks the code.ie

    %result = mce_loop {sub { my ($mce,$chunk_ref,$chunk_id) = @_; my %ret; for my $item (@{ $chunk_ref }) { my $ret=tags_get($item); $ret{$item->[1]}=$ret->{$item->[1]}; #say $ret{$_->[1]}; } $mce->gather(%ret); } } $fileprobe;

    thanks

      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

        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

      > '%result = mce_loop sub {'

      > Results in a syntax error

      this shouldn't be, the problem must be somewhere in your code.

      I looked into the code of MCE::Loop and it works like I guessed.

      That's what's essentially happening in the import

      DB<8> sub run (&@) {} DB<9> *mce_loop = \&run DB<10> mce_loop {print "code"} DB<11> mce_loop sub {print "code"} DB<12> mce_loop sub {print "code"},@_ DB<13> mce_loop 1 Type of arg 1 to main::run must be block or sub {} (not constant item) + at

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