Setting config file using constant

T

Tony

Hi,

I try to set a config file using constant. I put all the configuration in
Package/Config.pm as constant, and other program can get this
configuration by use Package::Config. It looks like this:

$ cat /var/www/lib/Package/Config.pm
package Package::Config;
use strict;
use constant ADMIN_NAME => 'My Name';
1;

$ cat /var/www/lib/Package/test.pl
#!/usr/bin/perl
use strict;
use lib "/var/www/lib";
use Package::Config;
print "Admin Name: " . $Package::Config::ADMIN_NAME . "\n";

Why this doesn't work? Please help, thanks very much.

Tony.
 
R

Roy Johnson

Tony said:
print "Admin Name: " . $Package::Config::ADMIN_NAME . "\n";

Why this doesn't work? Please help, thanks very much.

The answer is that constants are not variables, and so are not
referenced as variables. Drop the $ from your reference, and you will
get what you expect.

perldoc constant
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top