RE: How to put a global variable in a package, accessible to users of that package?



-----Original Message-----
From: Jeff Pang [mailto:pangj@xxxxxxxxxxx]
Sent: 31 October 2008 09:38
To: Perl Beginners [Beginners Perl]
Subject: RE: How to put a global variable in a package, accessible to
users of that package?


> Message du 31/10/08 10:25
De : "Stewart Anderson"
A : "mrstevegross" , beginners@xxxxxxxx

=== 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".

That looks interesting. How do people use that kind of constant
assignment.
That was not interesting. $foo::VAR is a wrong usage on his case. See
Shawn's answer.

Thanks Jeff, I had read Shawn's answer, I was asking about the
technique and how/where/why it gets used, not whether the person
asking for assistance had done it "correctly."


Information in this email including any attachments may be privileged, confidential and is intended exclusively for the addressee. The views expressed may not be official policy, but the personal views of the originator. If you have received it in error, please notify the sender by return e-mail and delete it from your system. You should not reproduce, distribute, store, retransmit, use or disclose its contents to anyone. Please note we reserve the right to monitor all e-mail communication through our internal and external networks. SKY and the SKY marks are trade marks of British Sky Broadcasting Group plc and are used under licence. British Sky Broadcasting Limited (Registration No. 2906991), Sky Interactive Limited (Registration No. 3554332), Sky-In-Home Service Limited (Registration No. 2067075) and Sky Subscribers Services Limited (Registration No. 2340150) are direct or indirect subsidiaries of British Sky Broadcasting Group plc (Registration No. 2247735). All of the companies mentioned in this paragraph are incorporated in England and Wales and share the same registered office at Grant Way, Isleworth, Middlesex TW7 5QD.
.



Relevant Pages

  • Re: in-package function vs macro
    ... #<PACKAGE foo> ... #<PACKAGE FOO> ... in a Lisp data structure, out the result of evaluating it. ... the package of *package* has no effect on the running code. ...
    (comp.lang.lisp)
  • Re: in-package function vs macro
    ... try to set back the last-package you are in the new package and the ... variable last-package was defined in the last-package. ... #<PACKAGE FOO> ...
    (comp.lang.lisp)
  • Re: import trick
    ... select undef, undef, undef, 0.25; ... for simplicity, i removed package ... package Foo is incompletely defined when ...
    (comp.lang.perl.misc)
  • Re: in-package function vs macro
    ... But this throws a strange error: ... try to set back the last-package you are in the new package and the ... variable last-package was defined in the last-package. ... #<PACKAGE FOO> ...
    (comp.lang.lisp)
  • Re: import fails if package namespace != module path
    ... module names and package names. ... I'm thinking that if I do go this route, I should avoid using import at ... sub import { ...
    (comp.lang.perl.misc)