I am trying to print the array but the out put contain only the last line of the array. the partial code is as follow.
open OUT, "> /myFile.txt"
or die "Couldn't open output file: $!";
foreach (@result) {
print OUT;
}
the out put is
List Z
which is the last line, but when I do print "@result" the out put is
List A
List B
List C so on...
I am little bit confuse why the results are different on the same array.
the problem is here
this should be
What you wrote overwrites the entire file for each iteration of the foreach(@result) loop.
What you are intending to do is append to it (“>>”).
“>>” appends, “>” overwrites.
Also take note of how i broke “>> /myfile.txt” into “>>”, “/myfile.txt”.
This is both more secure, and more robust for less specific applications of open.