Perl CSV数据中断文本中的换行符::CSV读取

Perl CSV数据中断文本中的换行符::CSV读取,perl,Perl,我有一些样本数据(来自谷歌电子表格) 然后我有一个简单的脚本: use Text::CSV; my $csv = Text::CSV->new({ sep_char => ',' }); $csv->column_names("title","url","description","contact_number","address1","address2","city","state","province","country","facebook","twi

我有一些样本数据(来自谷歌电子表格)

然后我有一个简单的脚本:

use Text::CSV;
my $csv = Text::CSV->new({
    sep_char => ','
   });
   $csv->column_names("title","url","description","contact_number","address1","address2","city","state","province","country","facebook","twitter","category_name");

my $file = './tmp/$USER->{Username}.csv';

open (WRITEIT, ">:encoding(utf8)", $file) or die "cant write $file: $!";
    print WRITEIT join("\n", @data). "\n";
close (WRITEIT) or die "cant write $file: $!";

open my $io, "<:encoding(utf8)", $file or die "$file: $!";

use Data::Dumper;

my $i = 0;
while (my $row = $csv->getline_hr($io)) {

    $i++;

    print Dumper($row);

}
它将描述中的\n作为换行符。这有什么办法吗

重要注意事项:默认行为是只接受范围从
0x20
(空格)到
0x7E
(波浪线)的ASCII字符。这意味着字段不能包含换行符。如果数据包含嵌入字段中的换行符,或
0x7E
(tilde)上方的字符,或二进制数据,则必须在调用
new
时设置
binary=>1
。为了涵盖最广泛的解析选项,您将始终希望设置二进制


哦,你是传奇人物!现在就像一个魔咒:)
use Text::CSV;
my $csv = Text::CSV->new({
    sep_char => ','
   });
   $csv->column_names("title","url","description","contact_number","address1","address2","city","state","province","country","facebook","twitter","category_name");

my $file = './tmp/$USER->{Username}.csv';

open (WRITEIT, ">:encoding(utf8)", $file) or die "cant write $file: $!";
    print WRITEIT join("\n", @data). "\n";
close (WRITEIT) or die "cant write $file: $!";

open my $io, "<:encoding(utf8)", $file or die "$file: $!";

use Data::Dumper;

my $i = 0;
while (my $row = $csv->getline_hr($io)) {

    $i++;

    print Dumper($row);

}
$VAR1 = 'Sample title,http://www.test.com,"A short description. Press Ctrl+Enter to create a new line
';
$VAR2 = '
';
$VAR3 = 'Like this",44 (0)1430 123 123,Some address line,Line 2,The city,The state,Some province,UK,facebook.com/test,twitter.com/test,Full Category/Path/To/Category or ID';