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

Re: use, require, do or what?

by pc88mxer (Vicar)
on Jul 30, 2008 at 18:57 UTC ( #701233=note: print w/replies, xml ) Need Help??


in reply to use, require, do or what?

When you declare a variable with my it won't be accessible in require-d code. One alternative is to use our instead of my:
our $var; require 'library.pl'; # library.pl contains: # $var = ... print $var, "\n";
However, modifying variables this way in not a great idea. Think about what the purpose of the module is. For instance, if you are using it to compute a function, make the module define a subroutine which is called by your program when it's needed. If is being used to define constants, then consider putting it in its own namespace and exporting the values.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://701233]
help
Chatterbox?
choroba recommends Paludan BogCafe, if it still exists
[karlgoethebier]: choroba: This: https://www. paludan-cafe.dk ???
[karlgoethebier]: I get "You are using an outdated version of Internet Explorer. For a faster, safer browsing experienceUpgrade" Ouch! i got safari...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2017-11-19 12:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (280 votes). Check out past polls.

    Notices?