Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Including Perl Tk module in a different location

by bugged123 (Initiate)
on Nov 23, 2011 at 21:25 UTC ( [id://939744]=perlquestion: print w/replies, xml ) Need Help??

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

Hi I am using activestate perl 5.14. How do I include Tk package when I store it in the same directory as my script.? I tried making some changes to Tk.pm in the Tk directory. But I am stuck at with this error

Can't locate loadable object for module Tk::Event in @INC (@INC contains: ./Tk/Event ./Tk C:/Perl/si te/lib C:/Perl/lib .) at Tk/Tk.pm line 14 Compilation failed in require at Tk/Tk.pm line 14. BEGIN failed--compilation aborted at Tk/Tk.pm line 14. Compilation failed in require at test.pl line 4. BEGIN failed--compilation aborted at test.pl line 4.

The code changes I made in Tk.pm are:
11 package Tk; 12 require 5.007; 13 use lib './Tk/Event'; #LINE I ADDED 14 use Tk::Event; 15 use AutoLoader qw(AUTOLOAD); 16 use DynaLoader; 17 use Cwd(); 18 use base qw(Exporter DynaLoader); 19 use File::Spec qw();
Thanks,

Replies are listed 'Best First'.
Re: Including Perl Tk module in a different location
by cavac (Parson) on Nov 23, 2011 at 22:48 UTC

    How do I include Tk package when I store it in the same directory as my script

    I usually unshift the paths into @INC on startup. Something like this should do the trick:

    #!/usr/bin/perl -w # First, do the usual dance of the stricture #---AUTOPRAGMASTART--- use 5.012; use strict; use warnings; use English qw( -no_match_vars ); use Carp; #---AUTOPRAGMAEND--- # Immediately after that, see of we need to spice # up @INC BEGIN { if($ARGV[1] eq "--debug") { print("Development INC activated\n\n"); unshift @INC, "/home/cavac/src/maplat_prodit/lib"; unshift @INC, "/home/cavac/src/maplat_framework/lib"; } } # Only after that, "use" the modules that could be in our debug path use Maplat::Web; use Maplat::Web::ProdIT; use XML::Simple;

    After that, the usual loading of modules works with a small difference: perl looks into the paths you unshifted first. If it doesn't find what it's looking for it goes on to whatever your systems default paths are. If it still doesn't find it, it reports an error.

    Don't use '#ff0000':
    use Acme::AutoColor; my $redcolor = RED();
    All colors subject to change without notice.
Re: Including Perl Tk module in a different location
by Marshall (Canon) on Nov 24, 2011 at 05:10 UTC
    Hi I am using activestate perl 5.14. How do I include Tk package when I store it in the same directory as my script.?

    Please forgive me, but I have to ask: why do you want to do that?

    Normally the best way with ActivePerl is to use the ppm tool (just type ppm at the command prompt to start the GUI version) and let the installer do its thing (puts Tk in the normal directory package directory structure). With 5.14 and I think even 5.12, Tk does not come as part of the base installation.

    There are ways to put Tk somewhere else, but this can get messy and before getting really involved in something complicated, understanding your rationale would help me because there may be another way to achieve what you want that is easier. This may be what is known as an XY problem..you are asking about how to do X, but what you really may need is to learn how to do Y.

Re: Including Perl Tk module in a different location
by perl.j (Pilgrim) on Nov 24, 2011 at 03:21 UTC
    Perl 5.14 and Tk do not mix well together. My suggestion, although not an answer, is to use Tk with 5.12. This migration was easy for me, as I had a similar issue.
    --perl.j

      Perl 5.14 and Tk do not mix well together.

      Sure they do

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-04-18 23:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found