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 )