I'm trying to increment a version number in a file using Perl. I want to change this line:
Bundle-Version: 1.0.2
to
Bundle-Version: 1.0.3
I thought I could do this using the following regex substitution:
perl -i -pe 's/(Bundle-Version: \d+.\d+.)(\d+)/$1$2+1/e;' MANIFEST.MF
But I get the following error:
Scalar found where operator expected at -e line 1, near "$1$2"
(Missing operator before $2?)
syntax error at -e line 1, near "$1$2"
Execution of -e aborted due to compilation errors.
Could somebody please advise what I am doing wrong here?
The
/eflag makes Perl treat the RHS as an expression, so you might fix your current code using's/(Bundle-Version: \d+.\d+.)(\d+)/$1 . ($2+1)/e;', but you can simplify it a bit and useSee the online demo.
Details:
Bundle-Version:- a fixed string\s*- zero or more whitespaces\d+\.\d+\.- two sequences of one or more digits and a dot\K- match reset operator that discards the text matched so far from the overall match memory buffer(\d+)- Group 1 ($1): one or more digits