You're missing two things:

1. As already mentioned, my vars are only visible within the same scope, pretty much no matter what you do. Use our instead if you want them to be visible in other packages or files.

2. Just changing my to our will allow you to reference the variables from your main program as $Config::database. If you want to be able to use just $database in the main program, then the Config module will need to export them, using Exporter:

package Config; use strict; use warnings; use base 'Exporter'; BEGIN { # Things to export by default - minimize this, if you use it at all our @EXPORT = qw( ); # Things to export when the calling code requests them our @EXPORT_OK = qw( \$database \$tmplfile \$blog_title ); # A handy way of grouping exported items our %EXPORT_TAGS = ( all => [ @EXPORT, @EXPORT_OK ] ); } our $database = 'data/site.db'; our $tmplfile = 'templates/index.html'; our $blog_title = 'example.com'; 1;
The main program, then, would start off with
#!/path/to/perl use strict; use warnings; use lib qw(/var/www/blogapp); use Config qw($database, $tmplfile, $blog_name); # or just # use Config qw(:all); # if you want everything the Config module exports

In reply to Re: Using packages to store global configuration vars by dsheroh
in thread Using packages to store global configuration vars by fuzzyping

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.