Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Perl provides a simple mechanism for specifying subroutine argument types called prototypes. Prototypes However, prototypes are problematic in many ways. First, prototypes do not affect functions defined using the & character. Furthermore, according to the perlfunc manpage [Wall 2011] states:

Method calls are not influenced by prototypes either, because the function to be called is indeterminate at compile time, since the exact code called depends on inheritance.

Prototypes are also not enforced by Perl's parser. That is, prototypes do not cause Perl to emit any warnings if a subroutine's invocation uses methods that don't match its prototype, not prototyped subroutine is invoked with arguments that violate the prototype.. Perl does not issue any warnings of prototype violations, even if the -w switch is used. They Finally, prototypes also can change function behavior and consequently should , by forcing scalar context when evaluating arguments that might not be scalars, or by forcing list context when evaluating arguments that might not be lists.

Because of these problems, subroutine prototypes must not be used when defining subroutines.

Noncompliant Code Example

...