http://qs321.pair.com?node_id=661101


in reply to Re: Full path to the current file?
in thread Full path to the current file?

Hi, ++davidrw
or even
$ perl -MFile::Spec -le 'print File::Spec->rel2abs( __FILE__ ) ;' /home/svenXY/-e # for a one-liner

File::Basename is not necessary here.
Regards,
svenXY

Replies are listed 'Best First'.
Re^3: Full path to the current file?
by davidrw (Prior) on Jan 08, 2008 at 16:01 UTC
    OP said I have a module that needs to know its path in order to access another file in the same location. -- the second step of File::Basename is to fulfill that requirement (even though he didn't directly ask for it).


    Other shell (bash) solutions:
    # setup cd /var/tmp/ touch foo f='../../var/tmp/foo' # for just the directory: d=`(cd ${f%/*} && pwd)` #or: d=`dirname $f` d=`cd $d && pwd` # for the filename (rel2abs): d=`dirname $f` d=`cd $d && pwd` f=`basename $f` f=`/bin/ls $d/$f`