[olug] Challenge With Perl Module Tk
jay at jays.net
Sat Aug 9 12:35:33 UTC 2003
CM Miller wrote:
> > ---
> > [root at phoenix root]# whereis perl
> > perl: /usr/bin/perl
> > [root at phoenix root]# find / -name Tk.pm -print
> > /usr/lib/perl5/site_perl/5.6.1/i386-linux/Tk.pm
> > ---
> > When you type "perl -V" is one of the paths in @INC
> > /usr/lib/perl5/site_perl/5.6.1/i386-linux
> Didn't see that line in the perl -V output. BUT, I'm
> not an expert on Perl either, and not sure what
> site_perl mean in the line above.
"site_perl" isn't special, it's just a directory name. Our whole goal
here is to make sure that perl knows where Tk.pm is when it runs. @INC
is perl's reserved name for the array which stores all the directories
it should look in for libraries when it needs one.
So, if your code says "use Acme::Foo::Fighters;", perl will go through
each directory in @INC looking for the directory "Acme" containing a
subdirectory "Foo" containing a module "Fighters.pm".
In this case, we're trying to make sure that perl can find
when it runs. perl -V shows us @INC, so we can see whether or not perl
will look in
when searching for Tk.pm.
> [root at phoenix root]# perl -V
Ok, the first thing to notice here is the directory where Tk.pm was
installed is not in @INC. When perl (the binary /usr/bin/perl) is
compiled on your machine a "default" @INC is compiled into it. From that
point on, whenever you install perl modules (Tk.pm) we hope that the
install routine for that module is smart enough to install the module
into a directory which is already in @INC. If not, perl will not find
the module. That's bad.
(Apparently the Tk.pm install is broken for your environment. You could
report to the author and/or patch the problem if you're feeling saucy.
Luckily, though, perl gives us a few ways of adding to @INC without
having to recompile /usr/bin/perl. One of those ways is the environment
Doh!! In your "perl -V" above %ENV is a hash of environmental variables
that are set. See how perl sees "PERL5_LIB", but that directory still
isn't in @INC? That's because I gave you the wrong variable name to set.
There's no underscore. If you
you should see that "perl -V" now includes that directory in @INC. I
apologize -- that was bad directions from me.
> Can you call this an error?
> [root at phoenix root]# /usr/bin/perl -MTK -e ''
> Can't locate TK.pm in @INC (@INC contains:
> /usr/lib/perl5/vendor_perl .).
> BEGIN failed--compilation aborted.
Oh yeah, that's definately an error. perl is not finding Tk.pm in @INC.
> What does @INC mean?
> Is @INC only related to Perl?
Yes, @INC is a Perl/perl thing. I hope I explained it OK.
> > You could reproduce the shell behavior w/ a little
> > script like this:
> > /usr/bin/perl -MTk < /dev/null > /dev/null 2>&1
> > if [ $? != 0 ]; then
> > echo "Error"
> > fi
> > Call that test.sh or whatever. Does it print
> > "Error"?
> I'm not sure what you are trying to do with the
> following in the script above? Please explain.
I was just breaking down the relevant code from how the shell script
"bastille" is envoking perl, which is failing to find Tk.pm in @INC.
> < > around /dev/null
Beats me. I didn't write "bastille". -grin-
> 2> &1
That redirects STDERR to wherever STDOUT is already going.
That hold the return value of the last program you executed. (I think.)
More information about the OLUG