perlcritic message: map used in void context

146 Views Asked by At

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?

1

There are 1 best solutions below

3
JGNI On BEST ANSWER

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;