Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

"Use Module" throws "Can't locate Module" even when inside a subroutine that is not not called.

Posted on 2003-11-23
3
Medium Priority
?
270 Views
Last Modified: 2010-03-04
I have a settings file that says $module = 0; Then in my script, I have code similar to:

if ($module == 1) {
  use Module;
  do stuff...etc, etc, etc

}

So, when I execute the script, I would think that it would not try to interpret "use module". However, I get an error saying that the module can't be located in @INC, etc... My question is, why does this happen...is it supposed to do that? I think I will just throw an eval around it, but I wanted to see if I was missing something.

Thanks.
0
Comment
Question by:emartin24
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 18

Accepted Solution

by:
kandura earned 400 total points
ID: 9807576
from the perlfunc manpage for 'use':
"It is exactly equivalent to
    BEGIN { require Module; import Module LIST; }"

from the perlmod manpage: "Because the use statement implies a BEGIN block, the importing of semantics happens as soon as the use statement is compiled, before the rest of the file is compiled. " and "In general, use Module () is recommended over require Module, because it determines module availability at compile time, not in the middle of your program's execution."

0
 

Author Comment

by:emartin24
ID: 9807634
So if I use require Module, in my example, it would only be compiled if $module == 1? Also, that means that it does not matter where a use statement is in Perl script...they will all be compiled in the begining?
0
 
LVL 18

Expert Comment

by:kandura
ID: 9807659
Yes, that is correct. But remember to do the 'import Module LIST' part if you want to import stuff from that module.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question