G
Greg Ercolano
I'm trying to figure out a way to load global variables using 'require'
with 'perl -w' enabled, but without getting "<varname> used only once" errors.
The only "solution" I've seen is to make sure all globals are referenced
more than once, but that gets hard to manage when you scale up the project.
My situation is a project of cgi-bin scripts, where there are several scripts
all wanting to load global settings from a single 'config.pl' file.
My current way of doing things is to make a 'config.pl' file that has the
global settings, ie:
$G::bgcolor = "#ff0000";
$G::cgibin = "/cgi-bin/MyApp/";
# ..etc..
1;
..and then all the actual scripts load these settings with 'require', eg:
#!/usr/bin/perl -w
use strict;
require "config.pl";
...
..that being in each of the potentially many script files that make up
the project.
Trouble is, if a script only refers to a global once, a "used only once"
error is printed, once per variable, which clogs the httpd daemon's error
logs with errors, one per variable.
The easy solution is to turn off the -w flag, but often it's useful to
leave it on during production to catch runtime errors.
From a developer's point of view, it's a real PITA to manually ensure
having no-op references for each global in /each/ script, eg:
#!/usr/bin/perl -w
use strict;
require "config.pl";
$G::bgcolor = $G::bgcolor; # silence 'used once' errors
$G::cgibin = $G::cgibin; # ""
..that becomes unmanageable fast.
Is there a 'right way' to do this without getting too 'hacky',
and without disabling -w? Maybe making the globals into a package?
Code examples welcome..
with 'perl -w' enabled, but without getting "<varname> used only once" errors.
The only "solution" I've seen is to make sure all globals are referenced
more than once, but that gets hard to manage when you scale up the project.
My situation is a project of cgi-bin scripts, where there are several scripts
all wanting to load global settings from a single 'config.pl' file.
My current way of doing things is to make a 'config.pl' file that has the
global settings, ie:
$G::bgcolor = "#ff0000";
$G::cgibin = "/cgi-bin/MyApp/";
# ..etc..
1;
..and then all the actual scripts load these settings with 'require', eg:
#!/usr/bin/perl -w
use strict;
require "config.pl";
...
..that being in each of the potentially many script files that make up
the project.
Trouble is, if a script only refers to a global once, a "used only once"
error is printed, once per variable, which clogs the httpd daemon's error
logs with errors, one per variable.
The easy solution is to turn off the -w flag, but often it's useful to
leave it on during production to catch runtime errors.
From a developer's point of view, it's a real PITA to manually ensure
having no-op references for each global in /each/ script, eg:
#!/usr/bin/perl -w
use strict;
require "config.pl";
$G::bgcolor = $G::bgcolor; # silence 'used once' errors
$G::cgibin = $G::cgibin; # ""
..that becomes unmanageable fast.
Is there a 'right way' to do this without getting too 'hacky',
and without disabling -w? Maybe making the globals into a package?
Code examples welcome..