I'm trying to replace text in a source file much like how the C preprocessor works. My approach is to parse constants and their values and populate a hash array with them. My problem is as follows:
In the source file, I have:
#define CONSTANT 10
#define CONSTANT_PLUS_ONE CONSTANT + 1
I use /^#define\s+(\w.*)\s+.*($key).*/
to match the second
line, but when I replace with s/$2/$defines{$key}/
, both
instances of CONSTANT are replaced, i.e.
#define CONSTANT 10
#define 10_PLUS_ONE 10 + 1
I'm something of a Perl novice, so I'm hoping someone can point me in the right direction, or if I've made a blatantly stupid mistake.