[sf-perl] A simpler perl technicality question.

yary not.com at gmail.com
Wed Dec 2 09:19:25 PST 2009


> Assuming that you're not using Moose, it's well known that you should
> 'use strict' and 'use warnings'.

For anyone unfamiliar with Moose, it turns on strictures & warnings
anyway. It's not a case of Moose being hurt by warn/strict, it's just
a little redundant. (I would say to still leave them in to make it
clear they are turned on, but then I've never used Moose much. I
suppose folks who use it regularly know it by better nature).

(Insert usual disclaimer about very short "throw away" scripts not
needing strict, can be quicker to code without it. You will discover
the border with experience, usually when you make a typo in a variable
name.)

As for "-w" vs "use warnings", "use warnings" gives you fine detail
over which warnings you want on or off- though that isn't all!
"perldoc perllexwarn" has a good description of the tradeoff. A
pointer to there can be found under "perldoc warnings", along with
this brief description:

    The "warnings" pragma is a replacement for the command line flag "-w",
    but the pragma is limited to the enclosing block, while the flag is
    global. See perllexwarn for more information.

that is, with "-w" you are turning on warnings for everything you
"use" as well, which may give you spurious warnings, if a module
wasn't designed with warnings in mind. It's analogous to "dynamic" vs
"lexical" scoping and so quite appropriate as a followup to the last
thread!

-y




On Wed, Dec 2, 2009 at 8:16 AM, George Hartzell <hartzell at alerce.com> wrote:
>
> I got a lot out of the discussion of local, Exporter, and symbol
> tables.  It got me thinking that all y'all might have something to say
> about a simpler question.
>
 I've habitually put them after my
> package declaration, but I've been reading through Ricardo Signes code
> (Dist::Zilla is pretty darn useful) and I've noticed that he puts them
> before the package distribution.  Perlmodlib says that 'Some pragmas
> are lexically scoped [...] Others affect the current package instead
> [...]' but doesn't do a good job explaining which are which.  Along
> the same lines I believe I've heard that doing '-w' is different than
> 'use warnings' but didn't file away the details.
>
> So, from a maximal safety point of view:
>
>  use strict; use warnings;
>  package FOO;
>
> or
>
>  package FOO;
>  use strict; use warnings;
>
> and how does -w fit in?
>
> Thanks for any clarity you can bring,
>
> g.
> _______________________________________________
> SanFrancisco-pm mailing list
> SanFrancisco-pm at pm.org
> http://mail.pm.org/mailman/listinfo/sanfrancisco-pm
>


More information about the SanFrancisco-pm mailing list