For one thing, it is very difficult to justify having any meaningfully large number of global variables. Having enough global variables as to make it annoying that one can't loop over them is indicative of terrible programming practice which should be corrected instead.taaveti wrote:it can be pretty useful in the other direction ($local_variable=$$global_name). It beats the hell out of writing some stupid get_global_variable function which consists solely of a giant switch statement with a case for every global variable you might want to access (although my coworker, who has somewhat more education and less real-world experience than I have, would say that the accessor function with an explicit list of every allowed variable name is actually the better practice).
In the rare case that a large number of global variables are needed, it is convention to put them into a hash table (and it is a criminally stupid language which does not allow iteration over the keys of a hash table). This is how POSIX environmental variables are accessed, for example; C uses getenv(char*) in stdlib, Python uses os.environ, Ruby uses ENV, etc.
If your real-world experience is telling you that you need to decide between a large number of global variables and a function centered around a switch statement, I think you need to pull yourself out of industry and step into a classroom.
In any case (and I'll think you'll agree), the danger of variable variables is not worth this non-benefit.