Is it correct that strict and warnings will not apply to checking the code in MYCLASS?

I

ioneabu

if I put

use strict;
use warnings;
use MYCLASS;

at the top of my program, is it correct that strict and warnings will
not apply to checking the code in MYCLASS? I did not know about this
and missed a big error using a global instead of a lexical. When I put
them in my class/module file, the error was picked up.
It may sound dumb but maybe worth mentioning.

wana
 
P

Paul Lalli

if I put

use strict;
use warnings;
use MYCLASS;

at the top of my program, is it correct that strict and warnings will
not apply to checking the code in MYCLASS? I did not know about this
and missed a big error using a global instead of a lexical. When I put
them in my class/module file, the error was picked up.
It may sound dumb but maybe worth mentioning.

strict and warnings are lexically scoped, and for good reason. Imagine
a module author who's code 'works' but is not strict-compliant, and/or
generates warnings. It would be very bad for the user of such a module
to be able to break the module simply by using strict and/or warnings in
his own code. Worse would be if the user of such a module was *unable*
to use the module without disabling strict and warnings in his own code.

When creating a module, you should put
use strict;
use warnings;
near the top of the .pm file (right under the package declaration).

See also:
perldoc warnings
for some features that are helpful to module authors.

Paul Lalli
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top