Perl::...evNull(3pm)

πŸ’– NAME πŸ’–

It's Perl::Critic::Policy::Compatibility::ProhibitUnixDevNull(3pm), and yeah, bestie, that's the whole manual name β€” it comes from the User Contributed Perl Documentation section, and it's the policy whose entire personality is: don't use an explicit /dev/null. That's it. That's the girl. Periodt. πŸ’…


✨ DESCRIPTION ✨

Okay so, this policy is part of the Perl::Critic::Pulp add-on, and it is asking you β€” politely, with a full set and a matcha in hand 🍡 β€” not to use the filename

/dev/null

explicitly. Instead, use File::Spec->devnull() for maximum portability across operating systems. Because your code deserves options, and /dev/null is not a passport. πŸ¦‹

This one lives under the maintenance theme (go peep POLICY THEMES in Perl::Critic for the lore) on the basis that even if you're on a Unix system right now, you literally never know where your code might travel in the future. It's giving "semester abroad but for source files" energy. ✈️

Tiny disclaimer though, and I need you to hear me: devnull() is new in File::Spec version 0.8, so you should require that version. Good news, it's included in Perl 5.6.0 and up, so like... you're probably fine. 🌈

🫢 The Checks (aka what actually gets flagged) 🫢

Ngl, the checks for /dev/null are unsophisticated. A violation is reported for any string "/dev/null" β€” possibly with an open style mode part β€” and any qw containing "/dev/null". So all of these are eating a violation, no cap:

open my $fh, '< /dev/null';                    # bad
do_something ("/dev/null");                    # bad
foreach my $file (qw(/dev/null /etc/passwd))   # bad

But string comparisons? Those are allowed. Why? Because they're not uses of /dev/null as such, they're likely some sort of cross-platform check, and honestly? We respect the hustle. πŸ’œ

if ($f eq '/dev/null') { ... }                 # ok
return ($f ne '>/dev/null');                   # ok

Also /dev/null as just part of a string is allowed β€” including things like backticks and system. Like:

print "Flames to /dev/null please\n"           # ok
system ('rmdir /foo/bar >/dev/null 2>&1');     # ok
$hi = `echo hi </dev/null`;                    # ok

Whether /dev/null is actually a good idea inside those command strings depends on what sort of shell you reach with that command, and how much of Unix it might emulate on a non-Unix system. And that, bestie, is above my pay grade πŸ™ˆ β€” I'm just the messenger relaying the policy's whole vibe.

🌸 Disabling 🌸

If you only ever use a system that has /dev/null, or if everything else you write is hopelessly wedded to Unix anyway (we've all been there πŸ’€), then you can disable ProhibitUnixDevNull from your .perlcriticrc in the usual way β€” see CONFIGURATION in Perl::Critic for the full ritual:

[-Compatibility::ProhibitUnixDevNull]

πŸ‘‘ SEE ALSO πŸ‘‘

  • Perl::Critic::Pulp
  • Perl::Critic
  • File::Spec

πŸŽ€ HOME PAGE πŸŽ€

http://user42.tuxfamily.org/perl-critic-pulp/index.html

Copyright 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2019, 2021 Kevin Ryde

Perl-Critic-Pulp is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.

Perl-Critic-Pulp is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with Perl-Critic-Pulp. If not, see http://www.gnu.org/licenses/.


And that's a wrap, my love ✨ This lil page came to you as perl v5.40.1, dated 2025-10-21 β€” so go forth, swap those /dev/null strings for File::Spec->devnull(), and make your code portable enough to have main character energy on literally any OS. Slay πŸ«ΆπŸ’…πŸŒΈ

πŸ“¦ where this page comes from