[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: for a Perl script to find a module



On Sun, Aug 01, 2004 at 12:23:17AM +0000, Thaddeus H. Black wrote:
> That is the problem.  After a fair bit of experimentation, here is my
> kludge of a solution thus far:
> 
>   BEGIN {
>     my $dir = `readlink -f $0`;
>     chomp $dir;
>     $dir =~ s/^(.*)\/.*?$/$1/ or $dir = '.';
>     unshift @INC, $dir;
>   }
>   use MyModule;
> 
> Does this kludge work?  Yes, it does seem to work, but it's a kludge,
> and it's not right.  It marshals a BEGIN block and a foreign utility
> program to trick perl into doing something simple and straightforward.
> Even if it were not ugly, it is sly and I cannot trust it.  How can I
> fix it?  All I want the script to do is to find a module.  The module
> is not sneaking around, hiding somewhere, after all; it stands right
> there at the script's shoulder, ready to serve.

Use the FindBin module. It's in the perl-modules package.

Cheers,

-- 
Colin Watson                                  [cjwatson@flatline.org.uk]



Reply to: