in reply to mod perl global initialization
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
you had to useINIT::thisvar; INIT::thatvar
or, better yetINIT::getInitvars()->{thisvar}; INIT::getInitvars()->{thatvar};
the Module could look like this (not working code, just a pseudo-perl example out of nothing):my $initHash = INIT::getInitvars() $initHash->{thisvar}; $initHash->{thatvar};
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.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 }
Edit: declared the static hashes, looks betterthat way;-)
regards,
tomte
An intellectual is someone whose mind watches itself.
-- Albert Camus
|
|---|