Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

warn if '=>' is used in "map EXPR,LIST' #23110

Open
djerius opened this issue Mar 14, 2025 · 3 comments
Open

warn if '=>' is used in "map EXPR,LIST' #23110

djerius opened this issue Mar 14, 2025 · 3 comments

Comments

@djerius
Copy link

djerius commented Mar 14, 2025

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.

@guest20
Copy link

guest20 commented Mar 14, 2025

People like you also enjoyed: Perl::Critic::Policy::BuiltinFunctions::RequireBlockMap

@djerius
Copy link
Author

djerius commented Mar 15, 2025

People like you also enjoyed: Perl::Critic::Policy::BuiltinFunctions::RequireBlockMap

Not as much as I enjoy block-less map!

@book
Copy link
Contributor

book commented Mar 15, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants