Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

eval "require $module"

Status
Not open for further replies.

1yura1

Programmer
Feb 7, 2003
36
UA
Hi All in forum.

If I need to check does my script anable to load module "Some::Module", I can write:
---
$module = "Some::Module";
if( eval "require $module" ){
$module->import();
}
else{
...
}
---
instead of "use Some::Module".

Can I (using "eval") check such requirement as:
use Some::Module qw($var1 $var2 ...);

?

Thanks.
 
If you are checking to see if symbol names are defined in another tablespace, you should use the defined() function.

use Some::Module; # (after your check I guess)

scream() unless defined($Some::Module::var1);
holla() unless defined(@Some::Module::var2);
lemme_hear_a_wha_wha() unless defined(%Some::Module::var3);
ralphie_in_da_hood() unless defined(%Some::Module::fox);

Make sense?

--jim
 
Hi All in forum.

Thanks Jim for the advise, but I ment smth. like this:

---
if ( eval "require Some::Module" ) {
Some::Module->import(qw($var1 $var2 $var_n));
}
else{
...
}
---

Yura.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top