I have Perl code to generate a has stored in two separate
.txt files that I want to execute while testing my module, but I can't seem to read them into the test.
I've tried using the in-built file reader :
open FILE, 'file.txt',
file is a storable file
None of these work in the test file (
.t format), but they do work in a normal
.pl file in the same directory How can I make it work in the test? I would use the
__DATA__ option, but I have two files and they are already in the hash format so can just be read straight in.
Edit: my code -
use Data::Dumper; use File::Slurp; my $table1 = read_file('tab1.txt'); my $table2 = read_file('tab2.txt'); print Dumper($table1); print Dumper($table2);
My output in test file:
$VAR1 = ''; $VAR1 = '';
and in the
$VAR2 are exactly like the contents of the '.txt' file, as I would expect.
Forgetting that there are hashes inside the files, that doesn't matter, I tried reading in a
test.txt file I made with a random string in it and it came out with:
$VAR1 = 'Testing commit - part 12';
which seems to indicate that it is reading in files that are in a different location, so therefore doesn't find my files. I tried including the directory as a
lib but that did not work.