Okay, I have tried to do this in Perl and have had little to no success...
Inside of a .cpp file I have the following text...
#define VARIABLE_A 32
#define VARIABLE_A 123
perl -MPOSIX -pe's/(\d+)/@ARGV/e if /define\s+VARIABLE_A\s+\d+/' file.h > file.h.2
mv -f file.h.2 file.h
When you recompile, you can use the -D option to set a value on the command line (at least in gcc and clang; presumably others). So the simplest solution is to just define VARIABLE_A on the command line.
gcc -D VARIABLE_A=123 file.cc
If you want to have a default, you just need to have something in your code to define VARIABLE_A when it hasn't been set on the command line.
#ifndef VARIABLE_A #define VARIABLE_A 32 #endif