On Jun 21, [EMAIL PROTECTED] said:
>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
You want a dispatch table:
my %functions = (
HTML_B => \&htmlbody,
HOME_B => \&homebody,
HEAD => \&header,
FOOT => \&footer,
# ...
);
Then, assuming our string is something like "HTML_B HEAD HOME_B FOOT", we
would do:
for my $funcname (split ' ', $actions) {
if ($functions{$funcname}) {
$functions{$funcname}->();
}
else {
warn "unsupported action '$funcname' attempted\n";
}
}
Another solution, though more dangerous, is eval().
my $code = 'print 10 + 24';
eval $code; # prints 34
--
Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/
RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
<stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.
[ I'm looking for programming work. If you like my work, let me know. ]
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]