Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: require() turns off strict?

by Vuen (Initiate)
on Jan 06, 2003 at 03:11 UTC ( [id://224520]=note: print w/replies, xml ) Need Help??


in reply to require() turns off strict?

Um, I'm confused. Does this apply to other calls to 'use'? I have a cgi script with 3 modules; I only 'use' the modules once in the perl script, and then the modules can all interact with eachother without having to 'use' eachother individually. Why doesn't this work with 'use strict'?

Replies are listed 'Best First'.
Re: Re: require() turns off strict?
by Gilimanjaro (Hermit) on Jan 06, 2003 at 10:35 UTC
    As I understand it 'use' actually does two things, both of them conditionally:

    1. Perform a sort of compile-time 'require' *only if* this module hasn't been 'use'-d before. A table of what modules have already been loaded is maintained in some variable that I don't recall at the moment.

    2. Call the 'import'-function (I think) *if* it is present in the 'use'-d package. This is performed on every occurence of 'use'. The import function is the one that can optionally export symbol-names (like your constants) to the calling package.

    Building your own import function is a hassle, so the easy way is to use the standard Exporter package... The man-page of the Exporter package can explain everything you want to know (and a lot more) about exactly how to use it. For starters, this should do:

    --file foo.pm--

    package foo; use Exporter; @ISA=qw(Exporter); @EXPORT=qw($const1 $const2 $const3); # rest of package including constant data
    If you'd just require'd the foo package, you would need to use $foo::const1 to access the constant.

    If you'd use'd the foo package, the same would still work, but you would also have access using $const1 from the calling package.

    Hope it helps...

      A table of what modules have already been loaded is maintained in some variable that I don't recall at the moment.
      That would be the %INC hash.
      (I think) *if* it is present in the 'use'-d package.
      Not quite. If you specify an empty import list as in use Module (); then its import() won't be called at all (not even with no parameters).

      Makeshifts last the longest.

Log In?
Username:
Password:

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

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

    No recent polls found