in reply to •Re: Re: •Re: How to use require...
in thread How to use require...
It was okay with use Login uncommented. The code I've is as follows
Also, I'm wondering why in the Login.pm it doesn't seem I need the usual exporting stuff as follows:######### index.pl #!C:/perl5.8/bin/perl.exe use strict; use warnings; use diagnostics; use CGI::Carp qw(fatalsToBrowser); use lib 'C:/apache/www/modules'; #use Login; use autouse Edit => qw(&login &login2); my %actions = ( default => \&default, login => \&login, login2 => \&login2 ); # Thanks to fruiture for pointing this out... $query = 'default' unless exists $actions{ $query }; &{ $actions{$query} } sub default { # show default page } ######### Login.pm use strict; use warnings; use diagnostics; use CGI::Carp qw(fatalsToBrowser); sub login { # display login page } sub login2 { # process login } 1;
# The package declaration and the code to # do the exporting are absent in Login.pm # Do I need to put them in? package Login; require Exporter; our @ISA = qw(Exporter); our @EXPORT = qw(&login &login2);
Got it to work. I do need the package declaration package Login at the top of Login.pm but I don't need to do any exporting as Login.pm is not used by other scripts for its functions. Also, instead of
I should haveuse autouse Edit => qw(&login &login2);
i.e. without the ampersand.use autouse Edit => qw(login login2);
Let me know if I've made any blunders :)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
•Re: Re: •Re: Re: •Re: How to use require...
by merlyn (Sage) on Jan 03, 2004 at 18:29 UTC | |
by kiat (Vicar) on Jan 04, 2004 at 01:48 UTC |