Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在某个地方看到,我们可以使用一些正则表达式来完成相同的任务,而不是在 perl 中使用 chomp。谁能告诉正则表达式会在 perl 中遇到 chomp
提前致谢
什么是从其参数字符串的末尾chomp删除值(或者如果没有参数)。所以等效的正则表达式将是:$/$_
chomp
$/
$_
s#\Q$/\E\z##;
请注意使用其他分隔符 fors///以避免$/变量出现问题。
s///
但是,使用这样的正则表达式没有任何好处,相反。在我看来,这是一个纯粹的学术问题。
您想要的 1000 次中至少有 995 次(除了制表符分隔数据的显着例外)
s/\s+\z//;
代替
chomp;
它处理尾随空格(不应该很重要)、Windows 行尾和 unix 行尾。