I have a code that I managed to narrow down to the next example of the smallest code.
First I have a plugh.pm module that is responsible for reading in the configuration file. The meat of this can basically be replaced with the following, which sets up one configuration item:
use strict; use warnings; sub cfgRead () { $main::cfg{"abc"} = "/usr"; } 1;
Then I have a main program that uses this module as follows, simply by calling a function to configure the configuration items, and then using one of these items in the routine:
#!/usr/bin/env perl use strict; use warnings; use 5.005; require File::Basename; import File::Basename "dirname"; push (@INC, dirname ($0)); require plugh; my (%cfg); sub subOne () { my $list = `ls -1 $main::cfg{"abc"}`; my @list = split (/\s+/, $list); my $fspec; foreach $fspec (@list) { print $fspec . "\n"; } } sub mainLine () { cfgRead(); subOne(); } mainLine();
Now, when I run this, I get the following output: the first line is a standard error, and the rest is standard.
Name "main::cfg" used only once: possible typo at /home/xyzzy/bin/xyzzy line 15. bin games include lib lib64 local sbin share src
The line he complains about is the creation of the subprocess ls -1 . My question is simple: so what? Yes, I use it only once, but why is this even a problem?
If I have never used it, itβs good, but I donβt understand why Perl warns me about using it only once.
I get a variable from an associative array and then use it to get a list of directories. Is there some weird Perl directive in which state variables should be used at least twice? Seven times? Forty-two? I am seriously at a standstill.
source share