Mnemonic Monks,

Running test code under 'strict' (of course).

Main script 'requires' a config file, where I set the values of a bunch of variables.

#!/usr/bin/perl -w use strict; use warnings; # load modules use CGI; use CGI::Carp qw(fatalsToBrowser); require 'config.pl'; my $var_1;
Where config looks like:
my $template_file; $template_file = "main.htm"; my $image_path; $image_path = "../../../images"; my %states; %states = ( AL => 'Alabama', AK => 'Alaska', AZ => 'Arizona' );
Perl gives me non-declaration warnings for all variables declared in the config file, but not for the ones declared in the main script.

Double checked - no typos.

If I remove "use strict" - it runs without complaint.
If I re-instate "use strict" and move the declarations from config into the main script - it also runs without complaint.

Can I not declare variables within a 'required' file when running under 'strict'??

Thanks.

*** UPDATE ***

After some fiddling, I realized that SOME variables weren't being flagged for non-declaration. By strange coincidence, only the varaibles used in in the main script in calls to the module Template are causing Perl to complain, even after switching to using "our" instead of "my".

*** UPDATE ***

Woops - more testing shows the first update not to be true - even variables not used in calls to Template are causing probs - but not all.




Forget that fear of gravity,
Get a little savagery in your life.

In reply to Variable declaration in 'required' file doesn't work under 'strict'? by punch_card_don

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.