I'm using Perl6::Form to generate a table and output it to a text file. No matter what I do, it seems, I can't output Windows line endings. I've tried local $OUTPUT_RECORD_SEPARATOR = "\r\n";
I've tried appending \r\n
to my format strings. No dice.
My code:
use English;
local $OUTPUT_RECORD_SEPARATOR = qq{\r\n};
my @column_headings = @{ shift $args->{'data'} };
my @rows = @{ $args->{'data'} };
my $header_format = join q{|}, (q/{]]]][[[[}/) x scalar @column_headings;
my $field_format = join q{|}, (q/{]]]]]]]]}/) x scalar @column_headings;
# formatting starts with headers followed by double line
my @format_data = ( $header_format, @column_headings, );
push @format_data, join q{|}, (q/==========/) x scalar @column_headings;
foreach my $row (@rows) {
push @format_data, ( $field_format, @{$row} );
}
my $text = form @format_data;
my ( $fh, $tempfile ) = File::Temp::tempfile;
$fh->print($text) or croak(qq/Failed to write to tempfile: $OS_ERROR/);
close $fh;
According to the docs,
The file returned by File::Temp will have been opened in binary mode if such a mode is available. If that is not correct, use the C function to change the mode of the filehandle.
As such, re-add the :crlf normally present on file handles opened in Windows using the following after the open but before the print.
$fh->binmode(':crlf');