Subject: | Text::CSV problem/question |
Date: | Tue, 6 Feb 2018 13:38:36 -0800 |
To: | bug-Text-CSV [...] rt.cpan.org |
From: | Lorien Stice-Lawrence <lorienstice [...] gmail.com> |
Hi,
Thanks for putting together such a useful module. I've used it in many
programs in the past. In the past it used to be the case that when I was
printing to a CSV file throughout my program (i.e. once at the beginning to
print the labels, and then looping through items and printing a line at a
time) the output csv file was continuously being edited as my program ran
and I could always peak inside the file to make sure the output looked
right. Similarly, if the program ran into a problem and failed (for a
reason unrelated to Text::CSV) I would still have all of the output I'd
printed from the previous loops. However, now no content is printed to the
csv file until the entire program has ended running, and if the program
stops prematurely (for a non-Text::CSV-related reason) none of the output
has been printed to the file at all. I'm at a loss as to why this is
happening because I'm using the same structure that I always have.
This is the basic structure of the loop I'm using. Is my issue due to a
change to Text::CSV or have I somehow been lucking out before?
Lorien
use Text::CSV;
my @rows;
my $csv = Text::CSV->new ( { binary => 1, eol => "\n", auto_diag => 1 } )
or die "Cannot use CSV: ".Text::CSV->error_diag ();
open(my $mycsv, ">", $outputfile) or die "$outputfile: $!";
my @columns=('var1', 'var1','var3');
$csv->print ($mycsv, [@columns]);
#loop
opendir (DIR, $folder) or die $!;
while (my $now_file = readdir (DIR)){
#various calculations which create $var, $var2, and $var3
#PRINT ALL OUTPUT TO A CSV FILE#
@my_array= ($var1, $var2,$var3);
$csv-> print ($mycsv, [@my_array]);
}
closedir DIR;
close $mycsv or die "$!";