Solved

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

Posted on 2003-11-23
3
263 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
  • 2
3 Comments
 
LVL 18

Accepted Solution

by:
kandura earned 100 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

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

777 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