I would like to be able to access a constant value from a name generated from a variable, e.g. if the variable contains ‘123’ then get the contents of a constant named ‘C123’.
After searching on here I can see that PHP is capable of doing that, but as I’m currently playing with Java, OCaml and Fortran I wondered if there was an equivalent for any of these languages?
This is generally referred to as reflection. (Here’s in the Wikipedia article on it.)
Basically it refers to the process of “letting the program inspect the program”.
If you search for reflection <your programming language of choice> you should be able to find plenty of guidance.
Btw, it is most often a sign of bad programming style to use reflection.