I’m trying to find a way to use [a regular expression] as a [variable name] or [a function name]. Do any programming or scripting languages offer this feature?
Example of the feature I want (using Java-like pseudocode):
int <<(my|a|an)(number|Integer)>> = 10;
//this variable has a regular expression as a name
function <<((print|write)(Stuff|Things|Words))>>(int myInt){
//this function has a regular expression as a name
System.out.println(myInt);
}
printStuff(myInt); //should have the same effect as the next line
writeWords(anInteger); //should have the same effect as the previous line
In Perl you could do such things for functions using
AUTOLOAD.Example:
Output:
Not sure about variables, but it’s probably possible as well.