calling a config file that has a hash within multiple perl scripts

HI

I have as hash within my script.pl file which look like this

my %verticals = ( 'auto_v1' => {
'tempdir' => '/var/www/html/temp/auto' ,
'svnurl' => 'http://svn.int.com/repos/a.com/branch/auto',
'excludes' =>
'uploaded_images|includes/config.php|admin/includes/config.p hp|.svn',
'tarpath' => '/var/www/html/temp/autotar/',
'tarname' => 'auto',
'rmtrootdir' => '/var/www/projects/auto/',
'rmttmpdir' => '/var/www/html/temp/autotar/',
'rmtserver' => '192.168.1.26',
'rmtuser' => 'root',
'rmtpass' => 'password'
},

'auto_v2' => {
'tempdir' => '/var/www/html/temp/auto' ,
'svnurl' => 'http://svn.int.com/repos/a.com/branch/auto',
'excludes' =>
'uploaded_images|includes/config.php|admin/includes/config.p hp|.svn',
'tarpath' => '/var/www/html/temp/autotar/',
'tarname' => 'auto',
'rmtrootdir' => '/var/www/projects/auto/',
'rmttmpdir' => '/var/www/html/temp/autotar/',
'rmtserver' => '192.168.1.27',
'rmtuser' => 'root',
'rmtpass' => 'password'
},

'auto_v3' => {
'tempdir' => '/var/www/html/temp/auto' ,
'svnurl' => 'http://svn.int.com/repos/a.com/branch/auto',
'excludes' =>
'uploaded_images|includes/config.php|admin/includes/config.p hp|.svn',
'tarpath' => '/var/www/html/temp/autotar/',
'tarname' => 'auto',
'rmtrootdir' => '/var/www/projects/auto/',
'rmttmpdir' => '/var/www/html/temp/autotar/',
'rmtserver' => '192.168.1.28',
'rmtuser' => 'root',
'rmtpass' => 'password'
}


);


### code follows
:
:



But it obviously looks too messy to add it all in one script.pl , as
i am going to add new keys and values to the hash , and as i am going
to keep adding to the hash later on i would need to automatically
generate my hash from a database, what is the best way to maintain the
config file which will contain the hash , and how do i use it within
multiple scripts .



--
Regards
Agnello D'souza

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Agnello George [ Fr, 29 April 2011 12:26 ] [ ID #2058960 ]

Re: calling a config file that has a hash within multiple perl scripts

Hi Agnello,

On Friday 29 Apr 2011 13:26:29 Agnello George wrote:
> HI
>
> I have as hash within my script.pl file which look like this
>
> ### code follows
>
>
>
>
>
> But it obviously looks too messy to add it all in one script.pl , as
> i am going to add new keys and values to the hash , and as i am going
> to keep adding to the hash later on i would need to automatically
> generate my hash from a database, what is the best way to maintain the
> config file which will contain the hash , and how do i use it within
> multiple scripts .

You should create a module for that: define a global variable and put a
subroutine that returns a reference to it. Note that you should probably use
YAML or JSON or perhaps JSYNC, for this configuration file if you are going to
use a module, because outputting Perl code from a larger program is error
prone, and people may be tempted to edit this code by hand.

Regards,

Shlomi Fish

--
------------------------------------------------------------ -----
Shlomi Fish http://www.shlomifish.org/
Why I Love Perl - http://shlom.in/joy-of-perl

I hope that you agree with me that 99.9218485921% of the users wouldn't bother
themselves with recompilation (or any other manual step for that matter) to
make their games run 1.27127529900685765% faster ;-) -- Nadav Har'El

Please reply to list if it's a mailing list post - http://shlom.in/reply .

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Shlomi Fish [ Fr, 29 April 2011 13:31 ] [ ID #2058961 ]
Perl » gmane.comp.lang.perl.beginners » calling a config file that has a hash within multiple perl scripts

Vorheriges Thema: better way of writing this script
Nächstes Thema: retrieving key from hash of hashes