in reply to Re^2: problem with paths to library files
in thread problem with paths to library files

I tried moving the
my $path
above the begin but it didn't work...
however, we have succeeded with the following:
use vars qw/$RealDir/; BEGIN{ $0 =~ m/(.*\/)/;#location of this file $RealDir = $1 . "libs"; }; use lib "$RealDir";

which works a treat.
thanks guys, excellent advice :)
all the best
johnc

Replies are listed 'Best First'.
Re^4: problem with paths to library files
by almut (Canon) on Jan 17, 2007 at 12:52 UTC

    I tried moving the

    my $path

    above the begin but it didn't work...

    Interesting... that's exactly the kind of thing I was worried about.

    I had tried:

    #!/usr/bin/perl use strict; use warnings; my $path; BEGIN { $path = $0; $path =~ s{[^\/]+$}{libs/}; } use lib $path; use MyLib;

    With the module ./libs/MyLib.pm being

    package MyLib; printf "Module %s loaded.\n", __PACKAGE__;

    running the script prints

    Module MyLib loaded.
    while commenting out the use lib $path gives the expected Can't locate MyLib.pm in @INC ...   IOW, it works for me.

    $ perl -v | head -2 This is perl, v5.8.8 built for x86_64-linux-thread-multi