I want to add functionality to a script using a module, but not do not
want to require the modules use. It looks like the following code
works, but is it the best way to achieve my goal (yes, I know TMTOWTDI)?
START CODE
#!/usr/bin/perl -w
use Gtk "-init";
use DBI;
$xls = eval "use Spreadsheet::WriteExcel ; return 1";
<snip>
if ($page == 0) { $ret = &save_file_as_txt($page, $widget) }
elsif (/\.xls$/i && $xls) { $ret = &save_file_as_xls($page, $widget) }
elsif (/\.tab$/i) { $ret = &save_file_as_tab($page, $widget) }
elsif (/\.csv$/i) { $ret = &save_file_as_csv($page, $widget) }
elsif (/\.unl$/i) { $ret = &save_file_as_unl($page, $widget) }
elsif (/\.htm$/i) { $ret = &save_file_as_html($page, $widget) }
elsif (/\.html$/i) { $ret = &save_file_as_html($page, $widget) }
else { $ret = &save_file_as_txt($page, $widget) }
<snip>
END CODE
The eval seems to load the module for the script (I get no errors when I
try to use the functions the module loads), but if it fails my program
doesn't (and $xls stays undef).
--
Today is Boomtime, the 6th day of Confusion in the YOLD 3167
Frink!