Pete Emerson wrote: > I think I'm going in circles. Sorry about the multiple postings. > The program barfs on 'use Tk' even though by the time I get to the 'use > Tk' the Tk module should be installed. > I tried doing require Tk; import Tk; > but then I get this message: > Bareword "MainLoop" not allowed while "strict subs" in use at... > > Is there a way to make perl not try to load the module until after it's > detected that the module is not installed, and subsequently gone ahead > and installed the module? > i.e. make the following code do what I want it to do ... > > eval { require Tk }; > if ($@) { > system('perl -MCPAN -e \'CPAN::Shell->install("Tk")\''); > } > use Tk;
you don't neccessary have to put everything in BEGIN. your code failed not because of the eval, if($@) thingy. it's because of the second "use Tk" (since it happen at compile time. ie, before Perl runs your eval stuff) line. if you were to change: eval{ require Tk; }; if($@){ system('perl -MCPAN -e \'CPAN::Shell->install("Tk")\''); #-- try again... eval { require Tk; }; if($@){ print "still??? installation failed...\n"; }else{ print "fine. Tk installed correctly\n"; } }else{ print "Tk already intalled\n"; } as you see see this is not better than putting in the BEGIN block but it does gives you another alternative. david -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]