Just open a file for output, and use its filehandle instead of *STDOUT{IO}
:
open my $FH, '>', 'file.csv';
$csv->print($FH, $_) for $table->rows;
Question
I am trying to write the csv->print out put to a file, the filename I want to use is in $_ and the data prints out from the csv->print command correct on screen. I just can't work out how to get it in a file.
$_ = $ARGV[0];
s/^[^=]*=//;
while (@ARGV) {
my $file = shift;
open my $IN, '<', $file or die $!;
my $html = do { local $/; <$IN> };
$te->parse($html);
}
for my $table ($te->tables) {
#print $_."\n";
open (NEWCSV, '>> '.$_);
print NEWCSV $csv->print(*STDOUT{IO}, $_) for $table->rows;
close (NEWCSV);
}
Thanks
Solution
Just open a file for output, and use its filehandle instead of *STDOUT{IO}
:
open my $FH, '>', 'file.csv';
$csv->print($FH, $_) for $table->rows;