in reply to Variable Declaration
Again, this code is directly from the mod_perl guide. So what they are offering here is basically a big hash, which is made global. And whatever modules you are creating are capable of making use of that existing hash, by referencing the full package variable name. They just make an alias to that package variable by doing "*c = \%My::Config::c". And anywhere in your program, you can access the data in that config file by just saying "$c{url}{docs}" and the like.# Config Module package My::Config; use strict; use vars qw(%c); # Create a hash containing our config data %c = ( dir => { cgi => "/home/httpd/perl", docs => "/home/httpd/docs", img => "/home/httpd/docs/images", }, url => { cgi => "/perl", docs => "/", img => "/images", }, color => { hint => "#777777", warn => "#990066", normal => "#000000", }, ); # Main program code (in a seperate file of course) use strict; use My::Config (); use vars qw(%c); *c = \%My::Config::c; print "Content-type: text/plain\r\n\r\n"; print "My url docs root: $c{url}{docs}\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Variable Declaration
by buckaduck (Chaplain) on Oct 19, 2001 at 18:25 UTC |