Perl怎样去除空白行?
来源:学生作业帮 编辑:神马作文网作业帮 分类:综合作业 时间:2024/11/11 09:06:47
Perl怎样去除空白行?
文本如下:
Hello,how are you?I'm fine thank you.
And you?I'm fine too.
The End
如何除空白行,使文本只剩下3行有字的?次序位置都不变.
文本如下:
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;
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;