For Programmers: Free Programming Magazines  


Home > Archive > PERL Miscellaneous > May 2005 > Testing if a module is there









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Testing if a module is there
gao_bolin@voila.fr

2005-05-25, 3:56 pm

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. Sinan Unur

2005-05-25, 3:56 pm

gao_bolin@voila.fr wrote in news:1117024492.664982.232780
@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

--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/c...guidelines.html
jl_post@hotmail.com

2005-05-25, 3:56 pm

gao_bo...@voila.fr wrote:
> 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

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com