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

  • SEARCH
  • Home
  • 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 1958186
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T08:01:29+00:00 2026-05-17T08:01:29+00:00

I am currently developping a multi-environment perl script. As you all know, environment configuration

  • 0

I am currently developping a multi-environment perl script. As you all know, environment configuration juggling could be quite a pain if badly done. As my perl script must allow some command line parameters in a configuration value overload purpose, i came with the following solution :

package Cfg;
use strict;
use warnings;
my $gEnvironment = "DEBUG";#"PRODUCTION";
my %gConfig = (
  DEBUG=>{MESSAGE=>"This is a dbg env.",URL=>"www.my-dbg-url.org"},
  PRODUCTION=>{MESSAGE=>"This is a prod env.",URL=>"www.shinyprodurl.org"}
);
my $gMessage = defined $gConfig{$gEnvironment} ?
  $gConfig{$gEnvironment}{MESSAGE} : die "Crappy environment";
sub Message { $gMessage = shift(@_) if (@_); $gMessage }
sub Url {
  defined $gConfig{$gEnvironment} ?
    $gConfig{$gEnvironment}{URL} : die "Crappy environment"
}
1;

So, the following script :

use strict;
use warnings;
use Cfg;
print Cfg::Message,"\n";
Cfg::Message("I'm a surcharged message.");
print Cfg::Message;

Would produce the next output:

This is a dbg env.
I'm a surcharged message.

The point is I want to define $gEnvironment’s value during the loading of the Cfg module.
This would allow me to use the same configuration module in all my environments.

Is this possible ?

  • 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-17T08:01:30+00:00Added an answer on May 17, 2026 at 8:01 am

    I believe a custom import method is what you’re after:

    package Cfg;
    
    our $gMessage;
    
    sub import {
        my ($package, $msg) = @_;
        $gMessage = $msg;
    }
    

    and somewhere else:

    use Cfg "some message";
    

    import is what perl will call when you use some module. Please see perldoc -f use for the details.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently developping an app that is going through all the files on a
I'm developing a multi-document application. Currently it uses MDI which is quite convenient for
I'm currently developing a multi-tiered application, using MVC3 and Spring.NET all of which is
Well, i'm currently developping a Google Chrome extension and i need to fetch all
I'm currently thinking of developing chess code with multi-player facility connected and played via
I'm new to magento. Currently i'm developing two ecommerce sites using multi-store option in
I'm currently developping an expression method (used in linq to entity queries) who has
I'm currently developping a search engine using Solr for an ecommerce website. So I
I'm currently developping a JavaEE application using glassfish, and I would like to save
I currently developing a multi-language interface for a Django project. But when I started

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.