我有以下PL和PM從ConfigReader.PM我如何使用`在Perl
文件Start.PL,ConfigReader.PM,BL.PM,Logger.PM
代碼提取our`變量
Package ConfigReader
use Config::Simple;
use Logger;
our $configIni;
sub OpenConfigIni()
{
my ($cfg_ini_path)[email protected]_;
&Logger::LogMsg("**** OpenConfigIni starts ****","info");
&Logger::LogMsg($cfg_ini_path,"info");
$configIni = new Config::Simple($cfg_ini_path);
&Logger::LogMsg("**** OpenConfigIni ends ****","info");
}
其中Logger.PM是我使用Log4Perl編寫的自定義模塊。從Start.PL
Start.PL BL.PM
Package BL
use strict;
use Logger;
use ConfigReader;
my %chash = %{$ConfigReader::configIni->param(-block => "UserDetails")};
代碼提取
代碼提取物的入口點到我的應用程序,啓動記錄儀,ConfigReader
use strict;
use ConfigReader;
use Logger;
use BL;
&Logger::InitiateLogger();
&ConfigReader::OpenConfigIni("My_Config.ini");
my %qhash = %{$ConfigReader::configIni->param(-block => "ABC")};
問題是
當我運行Start.PL時,代碼失敗,出現以下錯誤
Can't call method "param" on an undefined value at BL.pm line 9
Compilation failed in require at Start.pl line 19.
BEGIN failed--compilation aborted at Start.pl line 19.
(忽略行號)
據指着BL.pm
my %chash = %{$ConfigReader::configIni->param(-block => "UserDetails")};
下如果我在start.Pl評論use Bl
,腳本工作正常,這意味着
my %qhash = %{$ConfigReader::configIni->param(-block => "ABC")};
在Start.PL中正常工作
什麼,我想在這裏實現的是
1. Use the ConfigReader.PM for handling the configuration related
2. Make use of the our $configIni in all modules
3. Initialing the Logger and ConfigReader form start.pl whioch is the entry point here
可能是什麼問題就在這裏?
OK可以正常工作,當我把代碼'my%chash =%{$ ConfigReader :: configIni-> param(-block =>「UserDetails」)};'inisde一個方法。想知道爲什麼 – KK99
其Perl不是PERL –