in reply to Relative path in test file
$0 contains the name of the program as it was invoked. In your test cases, $0 will be:
perl t/mytest.t # t/mytest.t
perl mytest.t # mytest.t
So, if you want to open the file relative to your main program, use a path relative to $0. The FindBin module does that already, so you can just use that:
use FindBin; my $datafile = "$FindBin::Bin/data/test.txt"; open my $fh, $datafile or die "Couldn't open '$datafile': $!";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Relative path in test file
by ikegami (Patriarch) on Jul 07, 2022 at 19:12 UTC | |
by Anonymous Monk on Jul 07, 2022 at 20:35 UTC | |
by ikegami (Patriarch) on Jul 11, 2022 at 00:57 UTC |