谢谢,不过 "allow_whitespace = 1" 会把头尾的空白字符去掉,有什么办法把这些空白字符也保留下来吗?

    allow_whitespace
        When this option is set to true, whitespace (TAB's and SPACE's)
        surrounding the separation character is removed when parsing.



在 2011年3月11日 下午3:20, <[email protected]>写道:

>  主题: 如何不让Tie::Handle::CSV 
> 在字符串外加双引号""?<http://groups.google.com/group/perlchina/t/90f5ba18f871a36c>
>
>    许高飞 <[email protected]> Mar 10 04:58PM +0800 
> ^<#12ea3c9f22034749_digest_top>
>
>    请教一下大家,我在用Tie::Handle::CSV模块处理CSV文件时,发现其输出时会在字符串外加双引号""。
>    例如:
>    FOOBAR, Name, Type,
>    输出会变成:
>    FOOBAR," Name"," Type"," "
>    有什么办法不让Tie::Handle::CSV 在字符串外加双引号""吗?
>    代码例子见附件。
>
>
>
>
>    Robin Lee <[email protected]> Mar 10 05:39PM +0800 
> ^<#12ea3c9f22034749_digest_top>
>
>    因为有空格,所以加双引号是规范的做法,试试写成
>    FOOBAR,Name,Type,
>    也就是逗号后不加空格
>
>
>
>
>    Shu Cao <[email protected]> Mar 10 06:01PM +0800 
> ^<#12ea3c9f22034749_digest_top>
>
>    改成如下:
>
>    use Text::CSV_XS;
>
>    ...
>
>    my $csv_parser = Text::CSV_XS->new( {allow_whitespace => 1} );
>    my $fh_input = Tie::Handle::CSV->new("$inputfile", header => 1,
>    csv_parser => $csv_parser);
>
>    ...
>
>
>    --
>    Shu Cao
>
>
>
>

-- 
您收到此邮件是因为您订阅了 Google 网上论坛的“PerlChina Mongers 讨论组”论坛。
要向此网上论坛发帖,请发送电子邮件至 [email protected]。
要取消订阅此网上论坛,请发送电子邮件至 [email protected]。
若有更多问题,请通过 http://groups.google.com/group/perlchina?hl=zh-CN 访问此网上论坛。

回复