我正在从 MDaemon 迁移到 Google Apps。作为此过程的一部分,我将把所有用户的联系人和日历导出到 CSV 文件,然后将它们读入 perl 脚本并导入 Google Apps。
下面是在 vi 中打开“:set list”后显示的日历导出示例。
"Event 1","05/05/2009","0:00:00","05
/05/2009","23:59:00","True","True","05/04/2009","23:45:00",,,,"",,,"False","Normal",0$
"Event 2","09/21/2009","11:00:00","09/21/2009","11:30:00","False","False",,,"[email protected]","",,"Notes from=A0^M$
Vendor=A0",,"","False","Normal",1$
"Event 3","04/05/2010","0:00:00","04/05/2010","23:59:00","True","True","04/04/2010","23:45:00",,,,"",,,"False","Normal",0$
"Event 4","05/05/2010","0:00:00","05/05/2010","23:59:00","True","True","05/04/2010","23:45:00",,,,"",,,"False","Normal",0$
我遇到了以 ^M$ 结尾的行的问题,这些行应该是嵌入的行尾。我的 CSV 解析器 Text::CSV_XS 将它们解析为多行而不是一行。我怎样才能将 ^M$ 替换为 ^M?欢迎提出任何其他建议。
这是我的解析代码:
my $csv = Text::CSV_XS->new ({ binary => 1, eol => $/,auto_diag => 1 }) or
die "Cannot use CSV: ".Text::CSV_XS->error_diag ();
open my $fh, "<", $username . "-calendar.csv" or die $!;
while (my $row = $csv->getline ($fh)) {
print STDERR "NEW LINE: " . Dumper($row) . "END NEW LINE\n";
push @rows, $row;
}
$csv->eof or $csv->error_diag ();
close $fh;
更新 1: 以下是“文件”关于该文件的输出:
Non-ISO extended-ASCII English text, with very long lines, with CRLF, LF line terminators
答案1
s/\r\r\n/<br>/g
我使用 html 替换嵌入的换行符来使其工作<br>
。