Setting config file using constant

Discussion in 'Perl Misc' started by Tony, Oct 21, 2003.

  1. Tony

    Tony Guest

    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.
    Tony, Oct 21, 2003
    #1
    1. Advertising

  2. 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
    Tad McClellan, Oct 21, 2003
    #2
    1. Advertising

  3. Tony

    Roy Johnson Guest

    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
    Roy Johnson, Oct 21, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hardy Wang
    Replies:
    2
    Views:
    1,472
    Joe Fallon
    Jul 31, 2004
  2. Christopher M. Lusardi
    Replies:
    1
    Views:
    4,086
  3. Martin Magnusson
    Replies:
    2
    Views:
    503
    John Harrison
    Oct 8, 2004
  4. CSharpner
    Replies:
    0
    Views:
    1,015
    CSharpner
    Apr 9, 2007
  5. sinbad
    Replies:
    7
    Views:
    655
    sinbad
    Jun 19, 2008
Loading...

Share This Page