http://qs1969.pair.com?node_id=210349

xafwodahs has asked for the wisdom of the Perl Monks concerning the following question:

I have a script that can run with a GUI or not, depending on if the user specifies a -g option. The GUI is Tk based. Some of my users don't have Tk installed - they should still be able to run the script in console mode.
First, I tried:
if ($opt_g) { use Tk; <Tk code> }
but the 'use' would complain even of not finding the Tk module (for those without it installed) when the -g option was missing.
Then I tried:
if ($opt_g) { eval "use Tk; 1" or die "Tk not installed. Can't run GUI.\n"; <Tk code> }
This lets the script work in console mode, but with -g specified, the script fails to bring up the GUI, the script just exits back to the command prompt - no errors or anything.

Any help would be appreciated.