Unix/Linux Go Back    

CentOS 7.0 - man page for perl::critic::policy::controlstructures::prohibitmutatinglistfunctions (centos section 3)

Linux & Unix Commands - Search Man Pages
Man Page or Keyword Search:   man
Select Man Page Set:       apropos Keyword Search (sections above)


       Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions - Don't modify "$_"
       in list functions.

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

       "map", "grep" and other list operators are intended to transform arrays into other arrays
       by applying code to the array elements one by one.  For speed, the elements are referenced
       via a $_ alias rather than copying them.  As a consequence, if the code block of the "map"
       or "grep" modify $_ in any way, then it is actually modifying the source array.	This IS
       technically allowed, but those side effects can be quite surprising, especially when the
       array being passed is @_ or perhaps "values(%ENV)"!  Instead authors should restrict in-
       place array modification to "for(@array) { ... }" constructs instead, or use

       By default, this policy applies to the following list functions:

	   map grep
	   List::Util qw(first)
	   List::MoreUtils qw(any all none notall true false firstidx
			      first_index lastidx last_index insert_after

       This list can be overridden the .perlcriticrc file like this:

	   list_funcs = map grep List::Util::first

       Or, one can just append to the list like so:

	   add_list_funcs = Foo::Bar::listmunge

       This policy deliberately does not apply to "for (@array) { ... }" or

       Currently, the policy only detects explicit external module usage like this:

	   my @out = List::MoreUtils::any {s/^foo//} @in;

       and not like this:

	   use List::MoreUtils qw(any);
	   my @out = any {s/^foo//} @in;

       This policy looks only for modifications of $_.	Other naughtiness could include modifying
       $a and $b in "sort" and the like.  That's beyond the scope of this policy.

       There is discussion of this policy at <http://perlmonks.org/index.pl?node_id=743445>.

       Chris Dolan <cdolan@cpan.org>

       Michael Wolf <MichaelRWolf@att.net>

       Copyright (c) 2006-2011 Chris Dolan.

       This program is free software; you can redistribute it and/or modify it under the same
       terms as Perl itself.

perl v5.16.3		Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions(3)
Unix & Linux Commands & Man Pages : ©2000 - 2018 Unix and Linux Forums

All times are GMT -4. The time now is 05:38 AM.