Hello dear Monks,
I have a script which needs Image::Magick for some functions
but not all.
I'd like to disable these functions if Image::Magick is not installed
I tried to do something like :
pseudo-code
$is_magick = 0;
if ( is_installed Image::Magick ) { $is_magick = 1 }
and later
if ( $is_magick = 0 ) {
print "Image::Magick functions disabled";
}
else {
do stuff with Image::Magick ...
}
I found some post on perlmonks and other places but nothing works
stuff like
our $is_magick = 0;
eval 'require GD';
if ($@) {
# problems with GD, fall back to non-GD
} else {
# we have GD, go for it!
$is_magick = 1;
}
or
our $is_magick = 1;
BEGIN {
unless (eval "use Image::Magick") {
$is_magick = 0;
}
}
The first example didn't change $is_magick, the second one gives me an error 500.
How can do this ?
Thanks
Have a nice day !
updated fixed typo
"There is only one good, namely knowledge, and only one evil, namely ignorance." Socrates
-
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.