Hello,
I’m trying to increment numbers in a file – for instance, I would like to change the below 3 lines in a file by incrementing the numbers by 2 (or whatever the user gives).
Mikef<20:40>
JoeyS<23>
Samt<14:39>
So the end results should look like this:
Mikef<22:42>
JoeyS<25>
Samt<16:41>
I can do it in a command line using this:
> perl -pe 's/(\d+)/ 2 + $1 /ge' <filename>
But cannot do it inside of a program?
while ($line = <FILE>) {
$line =~ s/(\d+)/2 + $line/ge;
print NEWFILE $line;
}
The above scripting only replaces all numbers with "2"?
Can you tell me what I am doing wrong?
Thanks,
Mike