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
If I put a lot of subroutines in the BEGIN { } section, so that they
load at compile-time, what is the disadvantage?
BEGIN {
eval { require Tk; };
if ($@) {
# Do the NoGUI stuff here
exit;
}
sub LotsOfSharedSubsHere { }
}
use Tk;
print "GUI section.\n";
Lo
On Sep 5, Pete Emerson said:
>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.
'use Tk' happens at compile-time. The trick is to make the test happen at
compile-time
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
I think I may have answered my own question.
Is there a "better way" (TM) or a more efficient way?
eval { require Tk };
if ($@) { # module is NOT installed
# code here to make sure user is root and wants to proceed
system('perl -MCPAN -e \'CPAN::Shell->install("Tk")\'');
}
use Tk;
etc. etc.
How do I detect whether a module is installed or not?
For example, if a script is running as root, this would be useful:
if (Tk is not installed ) { # This is what I need.
print "Do you want to install the Tk perl module? (y/n) [n] >> ";
my $answer=;
exit if ($answer!~/^[Yy]/);
print "You