从输入文本中删除空格 [英] removing spaces from the input text

查看:67
本文介绍了从输入文本中删除空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

打开(HNDL,1.txt)或死亡无法打开文本文件;


while(< HNDL>)

{

if($。== 2)

{

print $ _;

$ _ = 〜s / \s // g;

print"删除空格$。 :",$ _;

}

}


输出 -

" 1 0 0"


实际上,我需要它为100。这样我就可以执行一些算术运算了。


如果使用替代品有愚蠢的错误,请原谅。我只是perl的初学者.. !!

open(HNDL, "1.txt") or die "Cannot open text file";

while (<HNDL>)
{
if($.==2)
{
print $_;
$_ =~ s/\s//g;
print "after removing spaces $. :",$_;
}
}

output --
" 1 0 0 "

Actually, I need it as "100". So that I can perform some arithmetic operations.

Excuse if there is silly mistakes in using substitute. I''m just a beginner in perl..!!

推荐答案

。== 2)

{

print
.==2)
{
print


_;
_;


_ = ~s / \s // g;

打印删除空格后
_ =~ s/\s//g;
print "after removing spaces


这篇关于从输入文本中删除空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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