logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

Perl::Critic::Policy::BuiltinFunctions::ProhibitVoidMap - Don't use "map" in void contexts.

Affiliation

       This Policy is part of the core Perl::Critic distribution.

Author

       Jeffrey Ryan Thalhammer <jeff@imaginative-software.com>

Configuration

       This Policy is not configurable except for the standard options.

Description

       "map" and "grep" are intended to be pure functions, not mutators.  If you want to iterate with side-
       effects, then you should use a proper "for" or "foreach" loop.

           grep{ print frobulate($_) } @list;           #not ok
           print map{ frobulate($_) } @list;            #ok

           grep{ $_ = lc $_ } @list;                    #not ok
           for( @list ){ $_ = lc $_  };                 #ok

           map{ push @frobbed, frobulate($_) } @list;   #not ok
           @frobbed = map { frobulate($_) } @list;      #ok

Name

       Perl::Critic::Policy::BuiltinFunctions::ProhibitVoidMap - Don't use "map" in void contexts.

See Also