Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: strict/warnings interference with global declarations

by davido (Cardinal)
on Nov 03, 2004 at 00:56 UTC ( #404800=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (1)
As of 2021-10-28 01:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (95 votes). Check out past polls.

    Notices?