Why do I get the warning Name "main::USER_INPUT" used only once: possible typo
when I run the following script?...
my $success_open = open USER_INPUT , '<:encoding(UTF-8)', $filehandle;
if(!$success_open)
{
die "Failed to open: $filehandle. $!";
}
while(<USER_INPUT>)
{
push @storage, $_;
}
close USER_INPUT;
Despite the warning, the script runs fine. It seems that I use USER_INPUT
three times: once when I open it as a filehandle, once when I read from it, and once when I close it. Do open
and close
not count as usage of USER_INPUT? My guess is that warnings
should count them. If it doesn't count them, then why?
I read several web pages about the once
warning, and they give solutions to suppress the warning, but they do not seem to give enough information to understand why/how once
occurs for my case:
- https://perldoc.perl.org/warnings.html
- Getting "... used only once: possible typo" warning when aliasing subroutines
- "name used only once" warning while using List::Util::reduce
- https://www.perlmonks.org/?node_id=1021888
- https://perlmaven.com/name-used-only-once-possible-typo
How/Where can I find more info about how the once
warning works? Is there a URL, Book, file, etc.? Maybe the code for once
is in my Perl installation somewhere, but I do not know where. I've also skimmed through the following books (including their indices) and did not find any detailed info about once
:
- Learning Perl
- Intermediate Perl
- Mastering Perl
- Programming Perl
- Perl Cookbook