Perl::...penArgs(3pm)
π Perl::...penArgs(3pm) β the manual, but make it cute
okay so bestie, welcome to Perl::Critic::Policy::Community::OpenArgs, which lives in the User Contributed Perl Documentation zone, and it's here to tell you one thing and one thing only: always use the three-argument form of open. periodt. π
β¨ NAME β¨
Perl::Critic::Policy::Community::OpenArgs β Always use the three-argument form of open π«Ά
πΈ DESCRIPTION πΈ
so the open() function is lowkey living a double life. you can call it in a two-argument form where the filename gets parsed to figure out the mode of opening β and that parsing can include piping input or output. (and yes, there's also a one-argument form, where that filename is retrieved from a global variable, but bestie it's the same magic either way. same chaos, different font. π)
and that's the problem: if the filename comes from user input, or could begin or end with a special character, you've basically handed out vulnerabilities like party favors. π
the three-argument form is the glow-up because it specifies the open mode as the second argument, so the mode is always distinct from the filename. no parsing, no surprises, no drama. β¨
open FILE; # not ok
open my $fh, "<$filename"; # not ok
open my $fh, '<', $filename; # ok
ngl, this policy is similar to the core policy Perl::Critic::Policy::InputOutput::ProhibitTwoArgOpen, but it goes one step further and additionally prohibits one-argument opens. she's thorough. she ate. π
π¦ AFFILIATION π¦
this policy is part of Perl::Critic::Community. it's giving community. it's giving found family. π
π CONFIGURATION π
not configurable, bestie β except for the standard options. that's it. that's the whole section. π
π AUTHOR π
Dan Book, dbook@cpan.org π
π COPYRIGHT AND LICENSE π
Copyright 2015, Dan Book.
this library is free software; you may redistribute it and/or modify it under the terms of the Artistic License version 2.0.
π SEE ALSO π
Perl::Critic
fr fr, if you were reaching for the two-arg or one-arg form β don't. it's giving vulnerability. just pass the mode. your future self will thank you. ππ
okay that's the whole vibe check, bestie β this was perl v5.40.1, dated 2025-03-22, and yes it's the Perl::...penArgs(3pm) page (the title got a lil truncated, she's shy π). go forth and open in three args. slay. π§β
π¦ where this page comes from
- debian trixie: libperl-critic-community-perl 1.0.4-1 Β· Artistic-2.0
- ubuntu resolute: libperl-critic-community-perl 1.0.4-1 Β· Artistic-2.0
- ubuntu stonking: libperl-critic-community-perl 1.0.4-1 Β· Artistic-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms