kiat has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to split up a script into a number of component scripts on the advice at All-in-one script vs independent scripts. In the code below, login.pl is loaded at the start of the script, whether or not it's actually needed.
That works but I would like to load login.pl as and when it's called. How do I achieve that? Something like:######### Main script ######### index.pl #!C:/perl5.8/bin/perl.exe use CGI qw(:cgi); my $query = get_param('action') || 'default'; # login.pl contains the subroutine do_login() require "login.pl"; my %actions = ( default => \&default, login => \&do_login ); &{ $actions{$query} } sub default { # show default page } ######### Auxiliary script ######### login.pl sub do_login { #process login } 1;
How do I accomplish what I'm trying to do above?######### Main script ######### index.pl #!C:/perl5.8/bin/perl.exe use CGI qw(:cgi); my $query = get_param('action') || 'default'; my %actions = ( default => \&default, login => \&login ); &{ $actions{$query} } sub default { # show default page } sub login { require "login.pl"; } ######### Auxiliary script ######### login.pl sub do_login { #process login } 1;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
•Re: How to use require...
by merlyn (Sage) on Jan 03, 2004 at 07:10 UTC | |
by kiat (Vicar) on Jan 03, 2004 at 07:33 UTC | |
by merlyn (Sage) on Jan 03, 2004 at 08:04 UTC | |
by kiat (Vicar) on Jan 03, 2004 at 10:59 UTC | |
by merlyn (Sage) on Jan 03, 2004 at 18:29 UTC | |
| |
|
Re: How to use require...
by fruiture (Curate) on Jan 03, 2004 at 09:54 UTC |