lakshmananindia has asked for the wisdom of the Perl Monks concerning the following question:
I have a file named Database.pm. I have a script named script.pl. The script.pl will look like the following.
use strict; use warnings; use Database; ...Some statements...
Now my requirement is, if the Database.pm is not available, I need to say that "Database.pm is not available" instead of perl printing the "Can't locate" error message.
I tried that with the help of eval as follows and it is working
use strict; use warnings; eval 'use Database'; if($@) { print "Database.pm is not available\n"; exit; }
I know that in perl we can achieve a task using many ways. Now I'm curious to know is there any other ways to do this?
The great pleasure in my life is doing what people say you cannot do.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: use statement in eval
by Gangabass (Vicar) on Mar 31, 2009 at 03:52 UTC |