Perl新行分隔符问题 [英] Perl New Line separator issue

查看:112
本文介绍了Perl新行分隔符问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用CR/LF分隔记录的文件,但是个别记录有时包含LF.

I have a file that uses CR/LF to separate records, but individual records sometimes contain a LF.

while (<$in>)
{ 
    #extract record data
}

我正在尝试如上所述读取此代码,并且(如我所期望的那样)这将拆分仅包含LF的记录.但是,我希望重新分配的 $/ 可以解决此问题,但是确实使我一次读取了完整的文件.

I am trying to read this code as above and this (as I would expect) splits the records that contain a LF only. I would however have expected that a reassigned $/ would resolve this issue but it does appear to cause the complete file to me read in one iteration.

$/ = "\r\n";
while (<$in>)
{ 
    #extract record data
}

这里有人可以提出可行的解决方案吗?

Anyone here who can suggest a working solution?

我正在Windows上使用Activestate Perl.

I am using Activestate Perl on Windows.

推荐答案

请稍后尝试

binmode($in);

这篇关于Perl新行分隔符问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆