如何在Perl中删除换行符和空格并将它们替换为空白字符?

问题描述

| 我如何用Perl编写一个正则表达式模式,它将像这样工作:
**If there is a new line**,after it,it will remove that new line character and all the whitespace characters after until it sees any character except for a white space character and will put just one whitespace character instead of them?
    

解决方法

替代算子
use warnings;
use strict;

my $s = \"foo\\n    bar goo\\nber\";
$s =~ s/\\n\\s*/ /g;
print \"$s\\n\";

__END__

foo bar goo ber
    ,我不确定我是否理解您的问题。尝试:
s{ \\n\\s+ }{ }gx