I want to replace a token in a text file with a number. The token is ‘<count>‘ and I want it to be replaced with the number of counts so far. For example:
This <count> is a <count> count. The <count> count increases <count><count><count>. <count><count><count><count><count><count>
becomes:
This 1 is a 2 count. The 3 count increases 456. 789101112
I’m not really sure how to do this, maybe with some loop?
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 ++; }
should do it for you. The /e at the end of the substitution makes all the difference.