Of the many ways you could go about doing this, one possible method is to write a configuration file for your program.

The mod_perl guide has a section on writing configuration files. While it is part of the mod_perl guide, by no means do you need to be using mod_perl to make use of it.

They take you from the quick, "false lazy" method of writing them, to a very nice, flexible system. As a spoiler, this is the style config file they end up leading you to. The code I'm pasting here is directly out of the mod_perl guide, I did not write it myself, although I did add a few comments:
# 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";
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.

Have fun!
-Eric

In reply to Re: Variable Declaration by andreychek
in thread Variable Declaration by ant

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.