Denzil Kruse wrote:
Hi,

I have a script for a cgi form that covers about 20
pages, and want to name a subroutine to handle each
page like this: page1, page2, page3, etc.

Once the script figures out which page it should go
to, I dont want to have to do this:

if ($page == 1) { &page1() }
if ($page == 2) { &page2() }
if ($page == 3) { &page3() }
.
.
.

I would like to call the subroutine with one
statement, something like this:

$page = $in->param('page');

&page$page()

but the "compiler" doesn't seem to substitute the
variable $page before figuring out the name of the
subroutine and it gives me an error.  I thought about
loading the subroutine referencees into an array, but
run into the same problem.

Is there a way to do this?  Or is there a better way
for the beginning part of the script to play traffic
cop and direct it to the right page?


Have you considered the CGI::Application module? It works essentially as you describe but has a good following, is likely better tested, and may provide a little more support structure.


http://search.cpan.org/~markstos/CGI-Application-3.31/lib/CGI/Application.pm

In any case the array method you describe should work, can you show us the code you have tried? You may just not be dereferencing your sub correctly. You might also consider a hash and drop the numeric (and confusing names) unless there really is an order to the pages.

http://danconia.org

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to