Kit*_*ers 0 windows perl line-endings
我正在使用Perl6 :: Form生成一个表并将其输出到文本文件.无论我做什么,似乎,我无法输出Windows行结尾.我试过local $OUTPUT_RECORD_SEPARATOR = "\r\n"; 尝试附加\r\n到我的格式字符串.没有骰子.
我的代码:
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;
Run Code Online (Sandbox Code Playgroud)
根据文件,
如果有这样的模式,File :: Temp返回的文件将以二进制模式打开.如果不正确,请使用C函数更改文件句柄的模式.
因此,在打开之后但在打印之前,使用以下内容重新添加通常存在于Windows中打开的文件句柄上的:crlf.
$fh->binmode(':crlf');
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
206 次 |
| 最近记录: |