warn if '=>' is used in "map EXPR,LIST'
Description
It would be very helpful if a warning were issued when the => operator is used in the map EXPR,LIST syntax, in order to avoid writing this code:
map $_ => false, @subplot
which is definitely not the same as
map { $_ => false} @subplot
which is what I really meant.
People like you also enjoyed: Perl::Critic::Policy::BuiltinFunctions::RequireBlockMap
People like you also enjoyed: Perl::Critic::Policy::BuiltinFunctions::RequireBlockMap
Not as much as I enjoy block-less map!
Block-less map fans like us must learn the subtle differences between the lists returned by these:
map $_ => false , @subplot # false, @subplot
map { $_ => false } @subplot # @subplot elements alternating with false
map +( $_ => false ), @subplot # @subplot elements alternating with false
map +{ $_ => false }, @subplot # hashrefs with key = a @subplot item, value = false
map { $_ => false }, @subplot # syntax error
Even though I love the expression form for its conciseness, I'll readily admit the block form is the safe and consistent one.
People like you also enjoyed: Perl::Critic::Policy::BuiltinFunctions::RequireBlockMap
Not as much as I enjoy block-less map!
I just noticed that perlfunc actually gives one example where you get to use the EXPR form! (Been overlooking this somehow, well.)
my %hash = map +( $_ => false ), @subplot; # this is EXPR and works!
my %hash = map { $_ => false } @subplot; # equivalent to...
The + is necessary, otherwise it is parsed as map $_, false followed by @subplot:
my %hash = map ( $_ => false ), @subplot; # false => undef
# (@subplot consumed by void context, which warnings will catch)
(I was curious when it got added so I did a git-blame... here.)