http://www.perlmonks.org?node_id=404800


in reply to strict/warnings interference with global declarations

require is a runtime feature. strict does a compiletime check. Since file2 used $var, but $var is declared in file1, and since file1 isn't 'loaded' until runtime, there's no way for strictures to know, when Perl compiles file2.pm, that $var was declared in file1. So you get a compiletime error.

Keeping track of what order things happen in, helps to figure out what's going wrong. Here's a quick rundown of the sequence of events:

  1. Perl compiles file2.pm with 'use strict' on.
  2. Perl discovers that you're using $var in file2.pm, but hasn't yet loaded file1.pl. Strict complains.

If you had put our $var;, or use vars qw/$var/; in file2.pm, strict wouldn't complain, and you'll be ok, so long as file1.pl isn't a different package.


Dave