For exampl开发者_高级运维e, I want to remove unwanted line with bbbb
aaaa
bbbb
cccc
dddd
I use the following perl regular expression to accomplish this.
$_ =~ s/bbbb//g;
The problem here is that a blank line is stays, for example
aaaa
cccc
dddd
I need to remove the unwanted text line and also the blank line.
You could simply include the newline in your regular expression:
$_ =~ s/bbbb\n//g;
This will result in:
aaaa
cccc
dddd
It seems to me that if you are reading this line by line you could just have your loop do this:
my @foo = (
"aaaa\n",
"bbbb\n",
"cccc\n",
"dddd\n" );
foreach my $line ( @foo ) {
next if ( $line =~ /^bbbb$/ );
# now do something with a valid line;
}
精彩评论