如何指示 Perl 将在特定字符上断开的多行视为单行?
例如,我有一个 txt 文件,其中多行调用在 & 符号上断开。
command1
command2
execute myscript &
opt1=val1 &
opt2=val2
...
打开文件时,有没有办法告诉 Perl 将这三行视为一行并忽略 &
?
For example, I have a txt file with multi line calls broken on an ampersand.
command1
command2
execute myscript &
opt1=val1 &
opt2=val2
...
While opening the file, is there a way to tell Perl to consider these three lines as if it were a single line and ignore the &
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
打开文件时没有。但在阅读时加入他们并不难:
Not when opening the file. But it's not too hard to join them while reading:
如果记录之间总是有多个换行符,请考虑使用记录分隔符来读取它们。然后,您可以快速检查 &,并执行拆分/连接:
If you always have multiple newlines between records, consider using the Record Separator to read them. Then, you can use a quick check for the &, and perform a split/join:
我假设您的输入具有合理的大小,因此将整个内容读入标量,清理它,然后处理更友好的结果。
输出:
I assume your input is of a reasonable size, so read the whole thing into a scalar, clean it up, and then process the friendlier result.
Output: