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;
In reply to How to use require... by kiat
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |