Clear questions and runnable code
get the best and fastest answer
Base script behavior on presence (or non-) of a moduleby chexmix (Hermit)
|on Dec 21, 2011 at 15:41 UTC||Need Help??|
chexmix has asked for the
wisdom of the Perl Monks concerning the following question:
Good morning Monks,
I am working on a script that will output datasets which users at astronomical observatories can then pick up and plot, say with OpenOffice (or Excel, or what have you).
It has to be pretty generic, that is,
1) the fields in the data have to be pretty dependably common to any of the environments where this script might be used;
2) the default output is just tab-delimited text files.
So far, so easy; however, what is giving me pause is
3) no non-core modules should be required. We can't predict what users will have nor whether they will be allowed to install anything ...
... what I'd like to do is code up routines that will actually go ahead and do graphical plotting if the user has the GD::Graph module installed, but still output the plain text files if s/he doesn't.
So I am thinking I should be able to have the script test whether GD::Graph is installed and, if it isn't, to print a useful message (a suggestion that the user install the module, say) ... but then to continue and generate the plain text files.
I have tried using eval, as follows:
... but this doesn't work: I don't seem to be able to get around the complaint that Fictitious::Module is not found.
Is there a clean way to do this?