On 11/22/11 Tue Nov 22, 2011 2:04 PM, "Chris Stinemetz" <chrisstinem...@gmail.com> scribbled:
> I am working on a Perl script that is getting quite lengthy so I thought I > would put the sub routines, hashes, and arrays in a seperate script from > the main. > > The program will run when I turn use strict off in the main script, but > when I turn it on the main script doesn't recognize the hash and > array delaration in the second script. Lexical variables (those declared with 'my') are not visible outside of their enclosing scope, which includes the file where they are declared. You may get away with just declaring the variables with 'our' instead of 'my' in both files. This makes them 'package globals', but passes 'use strict' and allows you to refer to them without a package name (%main::fieldMap). While this approach is OK for small programs, if your program is really getting lengthy, you may want to adopt a more object-oriented approach and define some real modules that separate and encapsulate the behavior of some of the entities in your program. You can then avoid some of the problems associated with global variables. See 'perldoc -f our' for more details. > > main script first few lines: If you really want help with this, you should really post a complete program. Not your "quite lengthy" program, but a short one (in this case two) that demonstrates the problem. I could write a couple of Perl scripts myself to demonstrate what 'our' will do, but why should I? I'm not the one with the problem. :) -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/