No, this is quite a simple problem actually.  Here's how.

my $alias = "home|htmlBody,Header,homebody,footer";
my ($name, $subs) =  split(/\|/, $alias);
my @subs = split(/\,/, $subs);
foreach $sub(@subs){
    my $return_val = &{$sub}($pass_in_vars);
}

    So the first part I assume you've got where you pull your strings into vars, but 
don't put the &
on the front of them.  Then what you are doing with &{$sub}($pass_in_vars); is you are 
taking the
string "htmlBody" or whatever and saying I want to execute a sub called whatever 
string is in $sub.
    You use the same method as when you are dereferencing say an array ref. For example

my $stuff = ["first element", "second element", "third element"];
my @thearray = @{$stuff};

    Same technique.

Regards,
David


----- Original Message -----
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, June 21, 2002 9:58 AM
Subject: calling sub based on database list?


Ok, I got sorta a hard question<I think> that involves calling randomly changing 
subrutines. What
I'm Trying to do is this.  5 libaries are required into my CGI(PERL) program Each of 
them has their
own set of subrutines.  Now when someone accesses my site they also send a page 
referance eg
"main.cgi?page=home"  What im trying to get my code to do is take 'home' and then 
start runing
subrutines based on a file entry that can be edited from my admin section of this 
site.  So basicly
the file looks like this.

home|&htmlBody,&Header,&homebody,&footer

So it should get the list of subrutined to call but I can not figure out how to call 
them since they
are strings and not hard coded into the code.  Basicly I can get the values and print 
them out but
not call them.  Does anyone have and tips for calling a sub using the name from a 
string?
perl.call('htmlBody') does not work as one site pointed out. I guess thats for 
something else all
together.  Thanx

Chris

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to