Perl has a large number of built-in functions; they are described on the
perlfunc manpage [Wall 2011]. Perl also has a handful of reserved keywords such as
while; they are described on the
perlsyn manpage [Wall 2011].
Do not use an identifier for a subroutine that has been reserved for a built-in function or keyword.
Noncompliant Code Example
This noncompliant code example codes a subroutine called
open(), which clashes with the
open() built-in function.
Perl (v5.12.1) actually invokes the built-in
open() rather than the newly crafted subroutine.
This compliant solution uses a different name for its subroutine; consequently, it behaves as expected.
DCL31-PL-EX0: This rule does not apply to object methods. Object methods are easy for the parser to distinguish from built-in functions or keywords because of their distinct syntax.
Using reserved keywords can lead to unexpected program behavior and surprising results.
|SEI CERT C Coding Standard
|DCL37-C. Do not declare or define a reserved identifier
|SEI CERT C++ Coding Standard
|DCL51-CPP. Do not declare or define a reserved identifier
|"Homonyms," p. 177
|Elliot Shank, Perl-Critic-1.116 Subroutines::ProhibitBuiltinHomonyms