Re: strict behavior with .pm



On 9/28/07, Chas. Owens <chas.owens@xxxxxxxxx> wrote:

The strict pragma is lexically scoped, so you need to use it again
after the package statement. It is probably a good idea to turn on
warnings as well.

To be sure, I don't think that's an accurate description of the
effects of lexical scoping.

Both 'strict' and 'warnings' are lexically scoped directives. That
generally means that the declaration takes effect at the end of the
declaring statement, and it continues until the end of the smallest
enclosing block or file. A package directive has no effect upon
lexical scope of other directives.

On the other hand, most ordinary modules are package scoped. You have
to "use Carp" separately in each package in which its imported names
are needed, for example; so it may need to appear more than once in a
single file. But 'strict' and 'warnings', when not enclosed in the
curly braces that make a smaller scope, take effect for the rest of
the file.

Using lexically scoped directives within a file (as opposed to at the
top of the file) is generally needed only when requesting something
extra. For example, requesting more warnings than the default ones.

So, as a general style guideline, each file needs to start with a
block of boilerplate, including both "use strict" and "use warnings"
directives.

Cheers!

--Tom Phoenix
Stonehenge Perl Training
.



Relevant Pages

  • Re: how to reuse sub
    ... > I've tried to put the sub in a separate file and call it from another as ... I did some functional modules before I started using package ... You can do it without the package statement, and a post I sent a few days ... use warnings; ...
    (perl.beginners)
  • Re: how to reuse sub
    ... >> I've tried to put the sub in a separate file and call it from another as ... I did some functional modules before I started using package ... > more careful OO work using the package statement. ... > use warnings; ...
    (perl.beginners)
  • Re: Sharing variables between modules
    ... use strict; ... use warnings; ... # Note that this must also come *before* the use Foo line. ... package Foo; ...
    (comp.lang.perl.misc)
  • Re: A bug with MacTex/Luatex [was Re: Using fourier with pdflualatex]
    ... package fourier is used and no warnings otherwise. ... unfortunate tendency to morph your current font into a t1 version of ...
    (comp.text.tex)
  • Re: aclocal and hello world
    ... > macros used in configure.ac. ... I've read somewhere, in a recent autoconf manual I believe, ... into the autoconf package where they more properly belong. ... Anyways, it's good that aclocal is outputting those warnings, cause ...
    (comp.unix.programmer)