如果我有Perl 4,如何切弦? [英] How do I chomp a string if I have Perl 4?

查看:94
本文介绍了如果我有Perl 4,如何切弦?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在连接到远程服务器的个人计算机上编写脚本.我认为远程服务器安装了Perl 4.0或更低版本,这就是为什么它无法识别相同的原因. chomp命令是否可以替代?

I am writing a script on my personal machine which is connected to the remote server. I think the remote server has Perl 4.0 or lesser version installed and that is why it is unable to recognize the same. Is there an alternative to the chomp command?

推荐答案

它不是确切的替代品,但您可以尝试:

It's not an exact replacement, but you could try:

$var =~ s/\r?\n?$//

这将删除CRLF(DOS),LF(Unix),CR(Mac?).

which will strip either CRLF (DOS), LF (Unix), CR (Mac?).

普通的chomp运算符总是为当前O/S剥离当前定义的$INPUT_RECORD_SEPARATOR.

The normal chomp operator always strips out the currently defined $INPUT_RECORD_SEPARATOR for the current O/S.

这篇关于如果我有Perl 4,如何切弦?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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