本文介绍了从输入文本中删除空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
打开(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..!!
推荐答案
这篇关于从输入文本中删除空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!