On Wed, May 28, 2003 at 12:05:41PM +0200 anthony wrote: > i have a script with my modules. > i.e > #!/usr/bin/perl > use strict; > use warnings; > use Config::IniFiles; > my $cfg = new Config::IniFiles( -file => "/path/configfile.ini" ); > use lib '/path/tomy/Module'; > use MyModule; > use TestModule; > > now i would like $cfg to be global , so that all module can use the same > variable, and i don't have to declare each time $cfg in the module. > If I do "our $cfg", i can't get the variable in the module,I tried but i > don't know how to get. > Any help is appreciated.
If you only have a few global variables, you don't need our() at all. Simply package-qualify the variable and it will also make 'use strict' happy: use strict; use warnings; use Config::IniFiles; $main::CFG = new Config::IniFiles( -file => "/path/configfile.ini" ); ... Uppercasing a global variable is a good idea to indicate that it is global. Now, if you want to access this variable from a module (that is, another namespace/package), all you have to know is in which package this global variable lives. In the above, this is package main, so in your module you'd have to write: $main::CFG->method; A shortcut exists in that global variables from package main can also be written as $::CFG->method; Looks odd and yet $::VAR is the same as $main::VAR. Tassilo -- $_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({ pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#; $_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]