mrstevegross wrote:
>
> I have a package named "Foo" in which I want to define some package-
> level constants (such as $VAR="soemval"). I want those constants
> available to users of package Foo, so the following code would work:
> 
> === foo.pl ===
> package foo;
> use constant VAR => "someval";
> 
> === bar.pl ===
> use foo;
> print $foo::VAR;
> 
> It doesn't appear to be working; it compiles ok, but it prints
> nothing. I thought it would print "someval".

The code as you show it will not work at all. The line

  use foo;

will throw the error "Can't locate foo.pm in @INC" because you have incorrectly
named it foo.pl.

To get your program working, save the module as 'foo.pm' instead, and change its
contents to

  use strict;
  use warnings;

  package foo;

  our $VAR = "someval";

  1;


HTH,

Rob


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to