Testing if a module is there

G

gao_bolin

I would like to be able to use a module if it is present, without
generating an error if it is not. Is there a technique in Perl similar
to the try/catch technique used in some other languages to do that?

Thanks

B.
 
A

A. Sinan Unur

(e-mail address removed) wrote in @g14g2000cwa.googlegroups.com:
I would like to be able to use a module if it is present, without
generating an error if it is not. Is there a technique in Perl similar
to the try/catch technique used in some other languages to do that?

perldoc -f eval

perldoc -f require
 
J

jl_post

I would like to be able to use a module if it is present,
without generating an error if it is not. Is there a
technique in Perl similar to the try/catch technique used
in some other languages to do that?


Let's say you wanted to include the Win32::Console module, but only
give a warning if the module was not found. You could try:

eval { require Win32::Console };
warn "Cannot load module Win32::Console: $@" if $@;

I hope this helps.

-- Jean-Luc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top