【发布时间】:2010-10-18 20:46:01
【问题描述】:
我想用数字替换文本文件中的标记。令牌是“<count>”,我希望将其替换为到目前为止的计数。例如:
This <count> is a <count> count.
The <count> count increases <count><count><count>.
<count><count><count><count><count><count>
变成:
This 1 is a 2 count.
The 3 count increases 456.
789101112
我不太确定该怎么做,也许有一些循环?
my $text = (the input from file, already taken care of in my script);
my $count = 1;
while( regex not found? )
{
$text =~ s/<count>/($count);
$count ++;
}
【问题讨论】: