如何匹配下一行?
sometext_TEXT1.yyy-TEXT1.yyy
anothertext_OTHER.yyy-MAX.yyy
想- repetative.text
从最后删除,但前提是它重复。
sometext_TEXT1.yyy
anothertext_OTHER.yyy-MAX.yyy
我的尝试
use strictures;
my $text="sometext_TEXT1.xxx-TEXT1.xxx";
$text =~ s/(.*?)(.*)(\s*-\s*$2)/$1$2/;
print "$text\n";
印刷
Use of uninitialized value $2 in regexp compilation at a line 3.
换句话说,为下一个寻找更好的解决方案split + match
......
while(<DATA>) {
chomp;
my($first, $second) = split /\s*-\s*/;
s/\s*-\s*$second$// if ( $first =~ /$second$/ );
print "$_\n";
}
__DATA__
sometext_TEXT1.yyy-TEXT1.yyy
anothertext_OTHER.yyy-MAX.yyy