Perl::...penArgs(3pm)

πŸ“¦
version 1.0.4 Β· 4 versions
, in debian trixie, ubuntu resolute, ubuntu stonking

πŸ’… 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 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