【发布时间】:2012-10-16 18:59:02
【问题描述】:
我正在尝试替换文本中的所有单词,除了数组中的一些单词。这是我的代码:
my $text = "This is a text!And that's some-more text,text!";
while ($text =~ m/([\w']+)/g) {
next if $1 ~~ @ignore_words;
my $search = $1;
my $replace = uc $search;
$text =~ s/$search/$replace/e;
}
但是,该程序不起作用。基本上我试图让所有单词都大写,但跳过@ignore_words 中的那些。我知道这是正则表达式中使用的变量的问题,但我无法解决问题。
【问题讨论】:
-
如果您复制
$text并对其进行替换,则您的脚本可以正常工作。
标签: regex perl search replace match