Search code examples
perlvoidperl-critic

perlcritic message: map used in void context


There is a Perl code line below where I get the message from perlcritic:

map { $total_ids += scalar @{$ids->{$_}} } @brands;

The message is:

"map" used in void context near 'map { $total_ids += scalar @{$ids->{$_}} } @brands;'

Can anyone help me to fix it?


Solution

  • map returns a list, which in void context is thrown away.

    As recommended by Perl::Critic::Policy::BuiltinFunctions::ProhibitVoidMap, turn your map into a foreach

     $total_ids += scalar @{$ids->{$_}} foreach @brands;