As the static globals aren't a concern, I'll concentrate on a proposal for your INIT.pl

I wouldn't use INIT.pl as global-variables repository. Instead I would define and export a sub in it, that'd assamble the dynamic init-stuff into a hash and return this. Instead of using

INIT::thisvar; INIT::thatvar
you had to use
INIT::getInitvars()->{thisvar}; INIT::getInitvars()->{thatvar};
or, better yet
my $initHash = INIT::getInitvars() $initHash->{thisvar}; $initHash->{thatvar};
the Module could look like this (not working code, just a pseudo-perl example out of nothing):
package INIT; use Exporter; use vars qw( %static_1 %static_2 ); @ISA = qw(Exporter); @EXPORT = qw(&getInitvars); @EXPORT_OK = qw(%static_1 %static_2); %static_1 = ( this => "that", ); %static_2 = ( that => "this", ); sub getInitvars { my $result = {}; # push the static stuff push @$result, %static_1; push @$result, %static_2; # create the dynamic stuff push @result, _dynamicStuff(); $result; } sub _dynamicStuff { # compute stuff and return a hash }
Using non-static, not-constant global variables is likely to create a maintenance nightmare; avoid them where possible; using a solution as the proposed isn't much more work, but easily expanded if your needs change.

Edit: declared the static hashes, looks betterthat way;-)

regards,
tomte


An intellectual is someone whose mind watches itself.
-- Albert Camus


In reply to Re: mod perl global initialization by Tomte
in thread mod perl global initialization by sliver

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.