Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: how to create a constant file and use it in other file

by pc88mxer (Vicar)
on Jul 16, 2008 at 00:13 UTC ( [id://697830]=note: print w/replies, xml ) Need Help??


in reply to how to create a constant file and use it in other file

Referring to $MyConst::const1 works for me:
use strict; use warnings; use MyConst; print $MyConst::const1, "\n"; # prints 1

Replies are listed 'Best First'.
Re^2: how to create a constant file and use it in other file
by perlfan99 (Sexton) on Jul 16, 2008 at 00:19 UTC
    sorry i just forget that i put "use strict;" in "MyConst.pm" file, without that line, it works; with that line, i got the compile error.
      Then just add:
      our $const1;
      to MyConst.pm (just before the Readonly declaration.)

      Update: To use a variable in another package without requiring a prefix, you would have to import the symbol from the other package. The standard way to do this is to have MyConst be a subclass of Exporter.

        is there a way to export all constants instead of listing each one of them? and also a way to importing all of in another file?
      oh, i am using perl v5.6.1

      can you use the constant data without prefixing it with the package name? ( $const1 instead of $MyConst::const1 )

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://697830]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (6)
As of 2024-04-18 04:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found