Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: require() turns off strict?

by pg (Canon)
on Jan 04, 2003 at 19:13 UTC ( [id://224293]=note: print w/replies, xml ) Need Help??


in reply to require() turns off strict?

You actually discovered the fact that, "use strict" has a per lexical body scope (and your package is just one type of lexical body). Try this piece of code:
@a = (1,2); print join(",",@a); { use strict; @b = (1,2); print join(",",@b); }
Perl would tell you that @b requires a package name, but it does not complain about @a, because "use strict" is only specified for that {} scope.

This actually makes sense. For example, you get a package from another person, and he didn't "use strict" in his package. Now you use his package in your package, and you specify "use strict". If this "use strict" is not per lexical body scope, but affects the whole script(remember his package is inside your script scope now.), Perl will probably refuse to run your script, because of all those problems in his package caused by your "use strict".

I remember we had a thread a while ago, about the fact that, "use encoding" has a per script scope, instead of a per lexical body scope. You may want to compare those two different types of scopes. I have a node on that topic.

Replies are listed 'Best First'.
Re: Re: require() turns off strict?
by BioHazard (Pilgrim) on Jan 05, 2003 at 15:22 UTC
    Hi there,

    Thanks for the great resonance. I might see a little bit logic in this case.
    Another point is that the second file was actually not a package but a simple .pl file in my example.
    But that doesn't seem to make a difference for strict.
    So I will try to include the strict pragma whenever a new logical or lexical body scope begins in order to guarantee "strict Perl programming".

    Greetings,
    BioHazard
    reading between the lines is my real pleasure
Re: Re: require() turns off strict?
by dragonchild (Archbishop) on Jan 06, 2003 at 22:11 UTC
    For example, you get a package from another person, and he didn't "use strict" in his package. Now you use his package in your package, and you specify "use strict". If this "use strict" is not per lexical body scope, but affects the whole script(remember his package is inside your script scope now.), Perl will probably refuse to run your script, because of all those problems in his package caused by your "use strict".

    Like CGI.

    ------
    We are the carpenters and bricklayers of the Information Age.

    Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://224293]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (5)
As of 2024-04-25 10:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found