[sf-perl] A simpler perl technicality question.

Joe Brenner doom at kzsu.stanford.edu
Wed Dec 2 13:38:06 PST 2009


George Hartzell <hartzell at alerce.com> wrote:

> So, from a maximal safety point of view:
>
>   use strict; use warnings;
>   package FOO;
>
> or
>
>   package FOO;
>   use strict; use warnings;

I doubt there's any real difference.

You might wonder if a package line acts as a lexical boundary -- I don't
*think* that it does but if it did, then putting strict and warnings
before the package line would be completely wrong.

So doing it the first way is (a) non-standard and (b) inspires FUD in
the mind of maintenance programmers.  I would further add that it might
confuse a poor, simple-minded IDE [1] that expects the package name to
be defined at the top of the file.

Also, the benefit of doing it the first way seems non-existent.
You don't need to do that to catch compilation problems with the
package line.

(And perhaps unfortunately, there's no warnings if you have a
package name that doesn't match the file name, or if you use a
problematic package name like "m" or "s")

> and how does -w fit in?

Like Yary said, you need to read perllexwarn for the real low-down...
but the way I would summarize it is that you don't need to worry about
that too much.  The rules of the warnings pragma were carefully
thought out to minimize surprise to people used to doing it the old way.

Myself, I create new perl files from templates, so they always have
the warnings and strict pragmas, and I no longer bother with -w in
the hashbang line, but I still use it when checking syntax:

   perl -Mstrict -cw  <filename>


[1] I just checked, and putting the pragmas before the package line
confuses perlnow.el.  If I create a script from a module like that, the
script isn't created with the "use" line to access the module.  Argh.



More information about the SanFrancisco-pm mailing list