Seeking some advice here. I finally got my centralized script to work, but I cannot get it to work with 'use strict' and I get warnings with '-w'. Whenever I use my central script, the script that uses it, looks something like:

$database = "dbname"; require '/home/sites/jdb.cgi'; # now I can do whatever with $dbh

So when I slap in the '-w' (err, really I start with it - no honestly! :)), I get the following errors:

Name "main::dbh" used only once: possible typo at ./sqltest.pl line 8.
Name "main::database" used only once: possible typo at ./sqltest.pl line 5.

And if I 'use strict', I get:

Global symbol "$database" requires explicit package name at ./sqltest.pl line 5.
Global symbol "$dbh" requires explicit package name at ./sqltest.pl line 8.
Execution of ./sqltest.pl aborted due to compilation errors.

I put in a 'main::' in front of the variable names and that does fix it (not the warnings), but is that the solution? Putting 'main::' in front of everything?

I've heard of this 'our' declaration, but I don't have the latest version of Perl to have that (but if that's the answer, I'd still like to know).

If you check out the linked node, you'll see why I have/want this centralized script and the reason I designed it that way. But I don't like not being able to use the '-w' and 'use strict' ... am I doomed to have it only one way or another? Or is there a better way?

My next move is to read through the perldoc on the strict pragma. I guess I don't really understand that. But I'd still like to know if there's a better way to design such a system. Thanks in advance for the enlightenment! I look forward to learning an elegant solution. :)

Jason


In reply to Good programming practice by Purdy

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.