From your problem description it's a bit unclear to me whether you mean that you simply want to locate a file relative to the location of your test script, or you mean that the filename string you work with in your script should be expressed as a relative path (e.g. absolute "/path/to/data/test.txt" vs. relative "../data/test.txt"). The former is more common and what Corion's reply is doing - though I would personally recommend using catfile from File::Spec instead of manually concatenating the paths for maximum portability. If you need the latter, which is sometimes useful e.g. when you have to test an API and make sure it handles relative filenames correctly, then you can take the previously mentioned approach and additionally apply abs2rel from File::Spec on the filename.


In reply to Re: Relative path in test file by haukex
in thread Relative path in test file by Dirk80

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.