Perl::...tStdin(3pm)
π NAME π
Okay bestie, this is Perl::...tStdin(3pm) β the manual page for Perl::Critic::Policy::InputOutput::ProhibitExplicitStdin. The whole vibe? Use <> or <ARGV> or a prompting module instead of <STDIN>. Periodt. π
πΈ AFFILIATION πΈ
This Policy is part of the core Perl::Critic distribution. Yup, it ships with the main character energy. β¨
π¦ DESCRIPTION π¦
Okay so here's the lore, bestie: Perl has a useful magic filehandle called *ARGV that checks the command line and if there are any arguments, opens and reads those as files. If there are no arguments, *ARGV behaves like *STDIN instead. That's the plot twist. π«Ά
This behavior is almost always what you want if you want to create a program that reads from STDIN. This is often written in one of the following two equivalent forms:
while (<ARGV>) {
# ... do something with each input line ...
}
# or, equivalently:
while (<>) {
# ... do something with each input line ...
}
If you want to prompt for user input, try special purpose modules like IO::Prompt. It's giving "there's a module for that" energy. π
π CONFIGURATION π
No extra knobs, no secret switches, no little config arc. This Policy is not configurable except for the standard options. That's the whole story. π
π CAVEATS π
Okay, important caveat time β pay attention, bestie. Due to a bug in the current version of PPI (v1.119_03) and earlier, the readline operator is often misinterpreted as less-than and greater-than operators after a comma. So this policy misses important cases like:
my $content = join '', <STDIN>;
because it interprets that line as the nonsensical statement:
my $content = join '', < STDIN >;
When that PPI bug is fixed, this policy should start catching those violations automatically. So like, it's not you, it's the parser. π
π CREDITS π
Initial development of this policy was supported by a grant from the Perl Foundation. Shoutout to them, no cap. π«Ά
π«Ά AUTHOR π«Ά
Chris Dolan <cdolan@cpan.org> β iconic behavior, honestly. π
π COPYRIGHT π
Copyright (c) 2007-2023 Chris Dolan
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of this license can be found in the LICENSE file included with this module
Mwah π β this page came from perl v5.42.0, dated 2024-10-23. Bye bestie! πβ¨
π¦ where this page comes from
- opensuse-leap 16.0: perl-Perl-Critic 1.156.0-bp160.1.1 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms