Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: using 'use' conditionally

by xafwodahs (Scribe)
on Dec 02, 2002 at 19:04 UTC ( [id://217022]=note: print w/replies, xml ) Need Help??


in reply to using 'use' conditionally

Here is a test script. Run it with a -g as the first parameter.

On a machine without Tk, it will correctly die.
On a machine with Tk, it *should* bring up a simple Tk window, but it exits instead. If I replace the 'require' and 'import' with the 'use', then it works.

if ($ARGV[0] =~ /-g/) { # do gui die "You need Tk." unless (eval("require Tk;")); #use Tk; require Tk; Tk->import; $mw = MainWindow->new; $mw->Button(-text=>"EXIT", -command=>sub{exit})->pack(-side=>"bottom", -fill=>"both"); MainLoop; print "gui done.\n"; } else { # do non-gui print "non-gui stuff\n"; }

Replies are listed 'Best First'.
(tye)Re2: using 'use' conditionally
by tye (Sage) on Dec 03, 2002 at 17:30 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://217022]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (3)
As of 2024-04-24 04:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found