Perl::Critic::Policy::ValuesAndExpressions::ProhibitLeadingZeros(3pm)

Perl::Critic::Policy::ValuesAndExpressions::ProhibitLeadingZeros3pm

Write "oct(755)" instead of "0755".

Affiliation

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

Overview

Perl interprets numbers with leading zeros as octal. If that's what you really want, its better to use "oct" and make it obvious.

    $var = 041;     # not ok, actually 33
    $var = oct(41); # ok
    chmod 0644, $file;                              # ok by default
    dbmopen %database, 'foo.db', 0600;              # ok by default
    mkdir $directory, 0755;                         # ok by default
    sysopen $filehandle, $filename, O_RDWR, 0666;   # ok by default
    umask 0002;                                     # ok by default
    use POSIX 'mkfifo';
    mkfifo $fifo, 0600;                             # ok by default
    POSIX::mkfifo $fifo, 0600;                      # ok by default

Configuration

If you want to ban all leading zeros, set "strict" to a true value in a .perlcriticrc file.

    [ValuesAndExpressions::ProhibitLeadingZeros]
    strict = 1

Releases

10 releases since Debian 5.0 (Lenny); the text changed 9 times.

  1. 5.0
  2. 6.0
  3. 7
  4. 8
  5. 9
  6. 10
  7. 11
  8. 12
  9. 13
  10. Arch

Author

Jeffrey Ryan Thalhammer <[email protected]>

From perl-perl-critic 1.156-3 in Arch Linux 2026-11-01. Parsed by carta from the page's man source.