PDA

View Full Version : Building proc names from strings then executing them


JDA
10-09-2006, 08:18 AM
I'm trying to build proc names from strings, and then have them execute. Here's an simple example...

string $strn = "Last";
$proc = ("show"+$strn+"Hidden");
$proc;

Is this allowed? If it is, the syntax is beyond me. Any help would be apprieated.

TIA
JDA

jtilden20
10-09-2006, 09:13 AM
If you put an "eval" around your proc, and your proc actually exists, then it should run it. If you use the eval, you need to ensure that your proc is in the global, and not local.


global proc foobar()
{
print "hello!\n";
}

// Make a string with your proc name
string $myProc = "foobar()";
eval($myProc);


You could probably write whole procedures dynamically that way, though I can't say I've ever had a use for that.

JDA
10-09-2006, 02:54 PM
Perfect! Thanks.
JDA

CGTalk Moderation
10-09-2006, 02:54 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.