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::Community::AmpersandSubCalls - Don't use & to call subroutines

Affiliation

       This policy is part of Perl::Critic::Community.

Author

       Dan Book, "dbook@cpan.org"

Configuration

       This policy is not configurable except for the standard options.

Description

       Ampersands ("&") were once needed to call subroutines, but in modern Perl they are not only unnecessary
       but actually change the behavior from what you may expect. Calling a subroutine with an ampersand ignores
       the subroutine's prototype if any, which may change what arguments the subroutine receives.
       Additionally, calling a subroutine as "&foo;" with no arguments will pass on the contents of @_ from the
       current subroutine, which may be quite surprising. Unless used intentionally for this behavior, the
       ampersand should simply be omitted.

         my $value = &foo();  # not ok
         my $sum = &foo(1,2); # not ok
         my $value = foo();   # ok
         my $sum = foo 1,2;   # ok

       This policy is a subclass of the core policy Perl::Critic::Policy::Subroutines::ProhibitAmpersandSigils,
       and performs the same function but in the "community" theme.

Name

       Perl::Critic::Policy::Community::AmpersandSubCalls - Don't use & to call subroutines

See Also

       Perl::Critic

perl v5.40.1                                       2025-03-22             Perl::Critic::P...persandSubCalls(3pm)

See Also