Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7196475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:47:07+00:00 2026-05-28T20:47:07+00:00

I have some code that I’ve managed to narrow down to the following smallest-code

  • 0

I have some code that I’ve managed to narrow down to the following smallest-code sample.

First I have a module plugh.pm which is responsible for reading in a 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 which uses that module as follows, simply calling the function to set up configuration items, then using one of those items in a subroutine:

#!/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 with the first line being standard error and the rest being standard output:

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 it’s complaining about is the ls -1 subprocess creation. My question is simply: so what? Yes, I only use it once but why is that even an issue?

If I was never using it, then fine, but I can’t see why Perl is warning me about only using it once.

I get the variable from the associative array and then use it to get a directory listing. Is there some sort of bizarre Perl guideline that states variables have to be used at least twice? Seven times? Forty-two? I’m seriously stumped.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T20:47:08+00:00Added an answer on May 28, 2026 at 8:47 pm

    There are a few odd things here.

    First: when you have use strict active, you will get a warning if you use a variable without declaring it, or referencing it by fully qualified name.

    What you have actually done is to declare a local %cfg with my() in xyzzy.pl, and then to reference a different, package-global variable %main::cfg (implicitly declared by using its fully qualified name).

    To make the reference link to the same %cfg that you declared, you should declare it our() to make it package-global. Then you can either reference it as $main::cfg{} in both places (or just $cfg{} from xyzzy.pl), or else you can declare it our() in plugh.pm as well (so that you can use the bare %cfg in both places).

    The odd thing is that you do have two references to that variable, so you shouldn’t get the warning. I think what has happened here is that the implicit declarations in two separate files are assumed to be separate variables.

    xyzzy.pl:

    require plugh;
    
    our (%cfg);
    
    sub subOne () {
       my $list = `ls -1 $cfg{"abc"}`;
       ...
    }
    

    plugh.pm:

    our(%cfg);
    sub cfgRead () { $cfg{"abc"} = "/usr"; }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code that I have created for an OnChange event which works
I have some code that is a result of pretty much my first effort
I have some code that runs a cmd command in C# which works really
I have some code that first selects an option value in a dropdown menu
I have some code that gives a user id to a utility that then
I have some code that uses the shared gateway pattern to implement an inversion
I have some code that raises PropertyChanged events and I would like to be
I have some code that looks like: template<unsigned int A, unsigned int B> int
I have some code that generates image of a pie chart. It's a general
I have some code that effectively does this : File file = new File(C:\\Program

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.