![]()
How do I execute a statement created at runtime?
Use the eval command. The
evalcommand is designed to allow execution of a string that is built at runtime.For example:
switch($timeOfDay) { case "morning": $shape = "circle"; break; case "afternoon": $shape = "sphere"; break; case "evening": $shape = "cone"; break; default: $shape = "cylinder"; } eval $shape -r 5; // create specified shape with radius 5.Alternatively, you could use
evalwith function syntax:You can also use the evalEcho and evalDeferred commands.