Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Setting config file using constant

Reply
Thread Tools

Setting config file using constant

 
 
Tony
Guest
Posts: n/a
 
      10-21-2003
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.


 
Reply With Quote
 
 
 
 
Tad McClellan
Guest
Posts: n/a
 
      10-21-2003
Tony <> wrote:

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

^
^ why is the dollar sign there?

> Why this doesn't work?



Because you put the dollar sign there.


--
Tad McClellan SGML consulting
Perl programming
Fort Worth, Texas
 
Reply With Quote
 
 
 
 
Roy Johnson
Guest
Posts: n/a
 
      10-21-2003
Tony <> wrote in message news:<>...
> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
concatenate a constant to constant string using macros sinbad C Programming 7 06-19-2008 05:28 PM
dll config and web.config and Label Expressions (binding label text to dll config settings) CSharpner ASP .Net 0 04-09-2007 09:00 PM
len(var) is [CONSTANT] equal to len(var) == [CONSTANT]? Tor Erik Soenvisen Python 14 11-23-2006 09:57 PM
"Non-constant" constant can't be used as template argument Martin Magnusson C++ 2 10-08-2004 08:41 AM
Understanding How To Use #ifdef Constant #define Constant Sequence In Multible Files Christopher M. Lusardi C++ 1 09-02-2004 07:43 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57