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

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;

but because of Windows, i will use the version with "softlink" in the filename.

In reply to Re^2: absolute pathname by maletin
in thread absolute pathname by maletin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.