LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-26-2007, 03:12 PM   #1
true_atlantis
Member
 
Registered: Oct 2003
Distribution: fedora cor 5 x86_64
Posts: 639

Rep: Reputation: 30
Perl module, global variables


what is the standard convention for specifying global, static variables in a perl module? for example, i want an '$admin' variable to be available at any point of execution which will contain an email address. i was thinking of just creating a 'GLOBALS' module that you can access variables by doing

use x::GLOBALS;
my $x=new x::GLOBALS;

$x->{'admin'};


and the 'new' will set all $self->{'admin'} like vars. how is this currently accomplished in the perl world?

thanks
 
Old 06-26-2007, 06:44 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,355

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Well, TMTOWTDI in Perl, but I do this just after my use ... declarations:

Code:
# Declare cfg pkg so we can refer to it anywhere
{
    package cfg;

    # Config file params
    %cfg::params = ();

    # Database interaction
    $cfg::dbh = '';
}
and then later access as
Code:
    if( $cfg::params{'DEBUG'} >= 1 )
    {
        print "load_ctrl()\n";
    }
or
Code:
    $sql = "blah";
    $sth = $cfg::dbh->prepare($sql);
Basically means that var is global across Perl file and always prefixed with pkg name.

Last edited by chrism01; 06-26-2007 at 06:45 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Global Variables In PHP? windisch Programming 2 06-12-2006 12:51 PM
g++ complains about global variables copolii Programming 3 09-18-2005 08:43 PM
Local vs Global variables wujee Programming 1 03-11-2005 11:43 PM
global variables in php champ Programming 2 10-13-2002 01:31 PM
global environmental variables antadam Linux - General 2 10-11-2001 06:36 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:03 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration