Hello perlidiot123, and welcome to the Monastery!

I'd like to convert this big thing to a complete use strict as well as convert my design philosophy to using strict 24/7.

Saying use strict actually invokes all of the various strict pragmata; currently there are three: refs, subs, and vars. So if you convert your code to use strict, you should approach this as three separate tasks:

  1. use strict 'subs'. This produces a compile-time error if the compiler finds a “bareword,” meaning an unquoted sequence of characters which the compiler cannot unambiguously identify as a variable name, function name, numeric constant, filehandle, etc. AFAICT, this can occur in only two cases: (1) a string which is unquoted; and (2) a subroutine call on a sub which is undeclared and is neither preceeded by & nor followed by (). In both these cases, the compile-time error will alert you to the problem, and the fix (quote the string or call the sub explicitly) is safe from adverse consequences or side effects.

  2. use strict 'vars'. This produces a compile-time error if the compiler finds a variable which has not been declared with my, our, state, or use vars, and which is not fully qualified with a package name. It is this aspect of strict which most Perl programmers think of when they think of use strict.

    I guess I'm just tired of hiding in the shadows of "Use everything, ie declare all $vars as OUR"

    Actually, if you do declare your global variables with our, you will satisfy the use strict 'vars' pragma and you will still gain some advantage over using undeclared package globals. A useful reference is Ovid’s 'our' is not 'my'. Of course, your long-term goal is to convert all the our variables (package globals) that are not shared between packages into my variables that cannot be (accidentally) so-shared. In doing this you will need to be careful to identify those variables which are meant to be shared. A text editor can help you here to some extent — if you have a variable $Foo::bar and the name $bar occurs only within the Foo package, you can be confident that it isn’t shared between packages — but where the same variable name is used across different packages, only a careful analysis of the code will tell you whether or not the variable is acutally shared.

  3. use strict 'refs'. This prevents the use of symbolic references (see How-can-I-use-a-variable-as-a-variable-name of perlfaq7). If your existing code does make use of symbolic references, the good news is that they can usually be fairly easily replaced with hard references. The bad news is that the use strict 'refs' pragma generates a run-time error (and not a compile-time error) when the interpreter encounters a symbolic reference. This means that if you get no errors under use strict, you can’t be sure that there are no symbolic references lurking undetected. If a symbolic reference appears in a seldom-visited execution path, your new code may appear to work for a while and then die unexpectedly. Once again, you need to make a careful analysis of the code to ensure that no symbolic references are being used.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,


In reply to Re: A use strict confession, with real questions. by Athanasius
in thread A use strict confession, with real questions. by perlidiot123

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.