Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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...


In reply to Re: Re: require() turns off strict? by Gilimanjaro
in thread require() turns off strict? by BioHazard

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found