Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: Howto Call Package from a Subdirectory

by arpad.szasz (Pilgrim)
on May 06, 2007 at 21:28 UTC ( #613854=note: print w/replies, xml ) Need Help??


in reply to Re: Howto Call Package from a Subdirectory
in thread Howto Call Package from a Subdirectory

unfortunately FindBin is not very reliable, especially in a persistent web environment (mod_perl). this has been discussed before:

the correct method, learned from the monks, that i currently use without problems in shell/web programs:

use vars qw( $RealBin ); BEGIN { use File::Spec::Functions qw( rel2abs splitpath catpath); $RealBin = catpath ((splitpath (rel2abs ($0)))[0,1]); } use lib "$RealBin/modules_src/"; # relative path from your Perl progr +am
:)))))

Replies are listed 'Best First'.
Re^3: Howto Call Package from a Subdirectory
by bart (Canon) on May 07, 2007 at 12:32 UTC
    That works, more or less, but gives me a warning, on Windows/perl5.6.1: Use of uninitialized value in concatenation (.) or string at [...]/lib/File/Spec/Win32.pm line 240.

    The reason is the lack of the third parameter to catpath.

    What's more, it still has a trailing backslash (probably a slash on Unix), which is not my idea of ideal. It might work, or it might fail on some platforms.

    The following code no longer produces the warning, but I still get the trailing backslash:

    $RealBin = catpath ((splitpath (rel2abs ($0)))[0,1], '');

    File::Spec is dumb.

      I now use this (only tested on Linux):

      our $RealBin; BEGIN { use File::Basename 'dirname'; use File::Spec::Functions 'rel2abs'; $RealBin = rel2abs( dirname( __FILE__ ) ); } use lib "$RealBin/lib";

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2022-12-05 18:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?