How can I find out the absolute path of my source-code? I wrote a test-script that uses the function caller():

#! perl -w # filetest.t # should be invoked from different directories (prove -r). use strict; use warnings; use Test::More tests => 2; use File::Basename; use File::Spec; my $filename = (eval{caller})[1]; diag("filename of this test-script: $filename"); my $dirname = dirname( $filename ); diag("dirname of this test-script: $dirname"); my $location = File::Spec->catfile( $dirname, 'non-existing-file' ); diag("testing a non existing file: $location"); cmp_ok( defined -f $location, '==', 1, 'this test should fail' ); $location = File::Spec->catfile( $dirname, 'filetest.t' ); diag("testing an existing file: $location"); cmp_ok( defined -f $location, '==', 1, 'this file should exist' );

my output of perl lib/t/filetest.t:

1..2 # filename of this test-script: lib/t/filetest.t # dirname of this test-script: lib/t # testing a non existing file: lib/t/non-existing-file not ok 1 - this test should fail # Failed test 'this test should fail' # at lib/t/filetest.t line 19. # got: # expected: 1 # testing an existing file: lib/t/filetest.t ok 2 - this file should exist # Looks like you failed 1 test of 2.
How can I get the absolute filename instead of "./lib/t/filetest.t"?


In reply to 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.