in reply to global variables defined in an external file

Show us the last thing you tried, or preferably, some small sample code that compiles, and represents what you are trying to do.

Alternatively, read up and follow the instruction in Exporter.

             "I'm fairly sure if they took porn off the Internet, there'd only be one website left, and it'd be called 'Bring Back the Porn!'"
        -- Dr. Cox, Scrubs

  • Comment on Re: global variables defined in an external file

Replies are listed 'Best First'.
Re^2: global variables defined in an external file
by fionbarr (Friar) on May 06, 2013 at 15:53 UTC
    use strict; use warnings; package x; use Exporter; my $VERSION = 1.00; my @EXPORT = (); my @ISA = qw(Exporter); my $a_template = "a12 a1 a4 a11 a2 a10 a12 a20 a15 a15 a1 a10 a1 a1 a +1 a2 a2 a1 a3 a3 a9 a1 a15 a2"; @EXPORT = qw(xxx $a_template); sub xxx {print "in package x\n";} 1;
      In addition to aitap's correction, I would recommend that you follow Exporter's advice:
      Exporting variables is not a good idea. They can change under the hood, provoking horrible effects at-a-distance, that are too hard to track and to fix. Trust me: they are not worth it.

      To provide the capability to set/get class-wide settings, it is best instead to provide accessors as subroutines or class methods instead.

                   "I'm fairly sure if they took porn off the Internet, there'd only be one website left, and it'd be called 'Bring Back the Porn!'"
              -- Dr. Cox, Scrubs

      my creates a block-scoped variable, while you need to create (using vars or our, as already suggested) a package-scoped variable (available in the symbol table), so it actually can be exported.

      Read Coping with Scoping for more information on this topic.