If I'm not mistaken, you want to require instead of use in your eval block. Here's how I did similarly a while back:
my $have_SWE;
BEGIN {
$have_SWE = 0;
eval { require Spreadsheet::WriteExcel };
unless ($@) {
Spreadsheet::WriteExcel->import();
$have_SWE = 1;
}
}
if ($have_SWE == 1) { ... }
If memory serves, I picked that up from something merlyn once said or posted.
cheers,
Don
striving toward Perl Adept
(it's pronounced "why-bick")
Update:
Super Search for "module installed" is what lead me to this thread, where I learnt of BEGIN, eval, and require.
Update:
After discussing with brother BUU, the lone advantage I can see of BEGIN... eval is that it allows you to include a more user-friendly message in the event that Tk isn't installed. As always, Wiser Monks Than I may very well rightly say that I'm fullabeans. {grin}
Untested, but perhaps a wee bit cleaner than my original code example:
my $have_Tk;
BEGIN {
$have_Tk = 0;
eval { require Tk };
$have_Tk = 1 unless ($@);
}
if ($have_Tk == 1) { ... }
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|