从 Perl 中的字符串中删除 CRLF (0D 0A) [英] Removing CRLF (0D 0A) from string in Perl

查看:48
本文介绍了从 Perl 中的字符串中删除 CRLF (0D 0A)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Perl 脚本,它在 Linux 上使用一个 XML 文件,并且在某些节点值中偶尔会有 CRLF(Hex 0D0A,Dos 新行).

I've got a Perl script which consumes an XML file on Linux and occasionally there are CRLF (Hex 0D0A, Dos new lines) in some of the node values which.

生成 XML 文件的系统将其全部写入一行,看起来好像偶尔会认为这太长并将 CRLF 写入其中一个数据元素.不幸的是,我对提供系统无能为力.

The system which produces the XML file writes it all as a single line, and it looks as if it occasionally decides that this is too long and writes a CRLF into one of the data elements. Unfortunately there's nothing I can do about the providing system.

我只需要在处理之前从字符串中删除它们.

I just need to remove these from the string before I process it.

我已经尝试过使用 perl 字符类、十六进制值等各种正则表达式替换,但似乎没有任何效果.

I've tried all sorts of regex replacement using the perl char classes, hex values, all sorts and nothing seems to work.

我什至在处理之前通过 dos2unix 运行了输入文件,但我仍然无法摆脱错误的字符.

I've even run the input file through dos2unix before processing and I still can't get rid of the erroneous characters.

有人有什么想法吗?

非常感谢,

推荐答案

典型的,折腾了大约 2 个小时,我在问这个问题的 5 分钟内就解决了..

Typical, After battling for about 2 hours, I solved it within 5 minutes of asking the question..

$output =~ s/[\x0A\x0D]//g; 

终于搞定了.

这篇关于从 Perl 中的字符串中删除 CRLF (0D 0A)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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