Perl怎样去除空白行?文本如下:Hello,how are you?I'm fine thank you.And you?I'm fine too.The End如何除空白行,使文本只剩下3行有字的?次序位置都不变.

来源:学生作业帮助网 编辑:六六作业网 时间:2024/05/12 17:13:14
Perl怎样去除空白行?文本如下:Hello,howareyou?I''mfinethankyou.Andyou?I''mfinetoo.TheEnd如何除空白行,使文本只剩下3行有字的?次序位置都不变.

Perl怎样去除空白行?文本如下:Hello,how are you?I'm fine thank you.And you?I'm fine too.The End如何除空白行,使文本只剩下3行有字的?次序位置都不变.
Perl怎样去除空白行?
文本如下:
Hello,how are you?I'm fine thank you.
And you?I'm fine too.
The End
如何除空白行,使文本只剩下3行有字的?次序位置都不变.

Perl怎样去除空白行?文本如下:Hello,how are you?I'm fine thank you.And you?I'm fine too.The End如何除空白行,使文本只剩下3行有字的?次序位置都不变.
可以用正则表达式替换,例子程序:
my $s="Hello, how are you? I'm fine thank you.
And you? I'm fine too.
The End";
print $s;
print "\n\n";
$s =~ s/\n+/\n/g;
print $s;