Saash Tech
Saash Tech

Reputation: 35

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?

Upvotes: 0

Views: 162

Answers (1)

JGNI
JGNI

Reputation: 4013

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;

Upvotes: 5

Related Questions