in reply to Re: absolute pathname
in thread absolute pathname
thank you. here is the difference between abs_path and rel2abs():
$ cd $HOME $ ln -s /tmp softlink $ perl softlink/mylog.pl
main:: path/mylog.pl (23)> abs_path=/tmp/mylog.pl main:: path/mylog.pl (26)> rel2abs=/home/maletin/softlink/mylog.pl MyLog::init /home/maletin/MyLog.pm (11)> INIT MyLog::path /home/maletin/MyLog.pm (16)> /home/maletin/MyLog.pm
$ cat /tmp/mylog.pl
#! perl -w # mylog.pl # using a package that print it's absolute filename. use strict; use warnings; use Log::Log4perl; use Cwd qw( abs_path ); use lib $ENV{HOME}; # location of MyLog.pm use MyLog; my $conf = q( log4perl.category.Log = INFO, Screen log4perl.appender.Screen = Log::Log4perl::Appender::Screen log4perl.appender.Screen.layout = Log::Log4perl::Layout::PatternLayout log4perl.appender.Screen.layout.ConversionPattern = %l> %m %n ); Log::Log4perl->init( \$conf ); my $log4perl_logger = Log::Log4perl->get_logger('Log'); my $abs_path = abs_path($0); $log4perl_logger->info("abs_path=$abs_path"); my $rel2abs = File::Spec->rel2abs($0); $log4perl_logger->info("rel2abs=$rel2abs"); MyLog->init($log4perl_logger); MyLog->path();
$ cat $HOME/MyLog.pm
but because of Windows, i will use the version with "softlink" in the filename.package MyLog; use strict; use warnings; my $my_logger = undef; sub init { my ( $class, $logger ) = @_; $my_logger = $logger; $my_logger->info('INIT'); } sub path { my $path = ( eval { caller(0) } )[1]; $my_logger->info($path); return $path; } 1;
|
---|