Perl, share package variable without Export
- by Mike
I'm creating a group of Perl scripts, and I would like to have one package store a group of constants. I don't want to export them using Exporter because there will be quite a few and I don't want to pollute the namespace. Since there will be so many, I don't want to require the user to be forced to manually specify which they will be using.
I think the best way to just use the packagename::var syntax, however it doesn't seem to be working as I expect it to. I illustrate this problem in the below code
This is settings.pm, the module that will hold the global settings
#!/usr/bin/perl
#settings.pm
use strict;
use warnings;
package settings;
our $foo="hello world";
1;
Below is the main script
#!/usr/bin/perl
#script.pl
use strict;
use warnings;
use settings;
print settings::$foo;
It gives this error message instead or printing hello world
Bad name after settings:: at ./script.pl line 8.