加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

用perl去掉Unicode换行字符

发布时间:2020-12-15 21:01:51 所属栏目:大数据 来源:网络整理
导读:?“ I have a string that is read from a text file but in Ubuntu Linux,and I try to delete its newline character from the end. I used all the ways. But for? s/n|r/-/ ?(I look whether it finds any replaces any new line string) it replaces

?“I have a string that is read from a text file but in Ubuntu Linux,and I try to delete its newline character from the end. I used all the ways. But for?s/n|r/-/?(I look whether it finds any replaces any new line string) it replaces the string but it still goes to next line when I print it. Moreover,when I used?chomp?orchop?string is completely deleted. I could not find any other solution. Do you have any idea? ”

大体意思就是文本最后包含Unicode字符集中的换行符,但是使用chomp无法解决。

解决方案:

? ? ?1. use 5.010; ?

? ? ??The correct way to remove Unicode linebreak graphemes,including CRLF pairs,is using the?R?regex metacharacter,introduced in v5.10.The?use encoding?pragma is strongly deprecated. You should either use the?use open?pragma,or use an encoding in the mode argument on 3-arg?open,or use?binmode.

? ? ? $data=~s/R//g;

? ? ? 2. 直接替换 ?$data=~s/[nr]+$//;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读