Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Relative path in test file

by haukex (Archbishop)
on Jul 07, 2022 at 20:34 UTC ( [id://11145346]=note: print w/replies, xml ) Need Help??


in reply to Relative path in test file

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.

Replies are listed 'Best First'.
Re^2: Relative path in test file
by Dirk80 (Pilgrim) on Jul 08, 2022 at 07:44 UTC

    Thank you all so much. This community here is so great.

    Corion's solution already worked great. But I extended it now by using $FindBin::RealBin and doing the concatenation by using File::Spec->catfile(...).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11145346]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-03-29 08:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found