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

Hi,

This is not really a Perl problem, so apologies for that.

I'm using Log::Log4perl and my script and its corresponding init-file are in a dusty directory under version control. I want to put a link the script under, say /usr/local/bin. The initialisation is done with

Log::Log4perl->init("log.conf");

How do I make sure that when the script is called via the soft link, the init-file is found? Ideally a local file would be used, otherwise the one in the version control.

Thanks for your help,

loris

Replies are listed 'Best First'.
Re: log4perl: finding initialisation file
by xorl (Deacon) on Dec 08, 2004 at 13:52 UTC
    You can use -e to check if a file exists. Something like
    if (-e "./log.conf") { Log::Log4perl->init("./log.conf"); } elsif (-e "../log.conf") { Log::Log4perl->init("../log.conf"); } else { Log::Log4perl->init("/etc/log.conf"); }
    Code is untested and I've been forced to use ASP for the last month so it could be totally wrong. I'm sure there is a more elegant solution too.