A
Andrey
Hello!
I have a problem and can't get it how to solve it.
When I'm using 'use Module;' in if..elsif statement I've got situation when
all modules is included.
For example (from code snippets bellow) if I call edit_info it makes
My::Info and My::Setting to be used and I can't use global variables in
edit_info, only in last elsif statement (change_settings).
Use of global variables is critical for this code.
I've read modperl, modperlib, Exporter but didn't find any solution.
Can anyone suggest me someting?
main.cgi
=======================================================
#!/usr/bin/perl -w
package main;
use strict;
use CGI::Apache qw/:standard/;
use CGI::Cookie;
use Apache:BI;
use lib qw (.);
use Rc::Config();
use vars qw(%cfg);
*cfg = \%Rc::Config::cfg;
use vars qw($dbh $q);
$q = new CGI;
if ($q->param('action') eq 'login')
{
&login();
}
elsif ($q->param('action') eq 'edit_info')
{
use My::Info;
&edit_info();
}
elsif ($q->param('action') eq 'change_settings')
{
use My::Settings;
&change_settings();
}
========================================================
My::Info.pm
========================================================
package My::Info;
use strict;
use lib qw(../);
use Rc::Config();
use vars qw(%cfg);
*cfg = \%Rc::Config::cfg;
use Exporter;
use vars qw(@ISA @EXPORT @EXPORT_OK);
@ISA = qw(Exporter);
@EXPORT = qw(edit_info $dbh $q);
@EXPORT_OK = qw();
use vars qw($dbh $q);
sub edit_info
{
..............................
}
1;
========================================================
My::Settings.pm
========================================================
package My::Settings;
use strict;
use lib qw(../);
use Rc::Config();
use vars qw(%cfg);
*cfg = \%Rc::Config::cfg;
use Exporter;
use vars qw(@ISA @EXPORT @EXPORT_OK);
@ISA = qw(Exporter);
@EXPORT = qw(change_settings $dbh $q);
@EXPORT_OK = qw();
use vars qw($dbh $q);
sub change_settings
{
..............................
}
1;
========================================================
I have a problem and can't get it how to solve it.
When I'm using 'use Module;' in if..elsif statement I've got situation when
all modules is included.
For example (from code snippets bellow) if I call edit_info it makes
My::Info and My::Setting to be used and I can't use global variables in
edit_info, only in last elsif statement (change_settings).
Use of global variables is critical for this code.
I've read modperl, modperlib, Exporter but didn't find any solution.
Can anyone suggest me someting?
main.cgi
=======================================================
#!/usr/bin/perl -w
package main;
use strict;
use CGI::Apache qw/:standard/;
use CGI::Cookie;
use Apache:BI;
use lib qw (.);
use Rc::Config();
use vars qw(%cfg);
*cfg = \%Rc::Config::cfg;
use vars qw($dbh $q);
$q = new CGI;
if ($q->param('action') eq 'login')
{
&login();
}
elsif ($q->param('action') eq 'edit_info')
{
use My::Info;
&edit_info();
}
elsif ($q->param('action') eq 'change_settings')
{
use My::Settings;
&change_settings();
}
========================================================
My::Info.pm
========================================================
package My::Info;
use strict;
use lib qw(../);
use Rc::Config();
use vars qw(%cfg);
*cfg = \%Rc::Config::cfg;
use Exporter;
use vars qw(@ISA @EXPORT @EXPORT_OK);
@ISA = qw(Exporter);
@EXPORT = qw(edit_info $dbh $q);
@EXPORT_OK = qw();
use vars qw($dbh $q);
sub edit_info
{
..............................
}
1;
========================================================
My::Settings.pm
========================================================
package My::Settings;
use strict;
use lib qw(../);
use Rc::Config();
use vars qw(%cfg);
*cfg = \%Rc::Config::cfg;
use Exporter;
use vars qw(@ISA @EXPORT @EXPORT_OK);
@ISA = qw(Exporter);
@EXPORT = qw(change_settings $dbh $q);
@EXPORT_OK = qw();
use vars qw($dbh $q);
sub change_settings
{
..............................
}
1;
========================================================