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
Solved

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

Posted on 2003-11-23
3
264 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Remove Malware code from PHP file 6 90
Perl, group, sort, count question 6 140
Excel to CSV conversion with specific columns 5 84
perl: Cleaning meta tags using RegEX 12 82
I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…

791 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