Perl的Config :: Simple似乎对我不起作用

时间:2014-01-03 03:21:02

标签: perl

我正在尝试使用以下内容从配置文件中读取参数,但这似乎不起作用。我正在尝试从文件中读取信息(只要它是人类可读的,我就可以使用任何格式)。在下面的例子中,我使用的是ini格式。

 sub getPropInFile {
    my (    $pFile, #property file
            $pName  #property name
    ) = @_;
    #Debug messages
    print "DEBUG:: File Name  => $pFile\n";
    print "DEBUG:: Param Name => $pName\n";

    #Create a new Config object
    my $cfg = new Config::Simple();
    #Open file
    $cfg->read($pFile) or die $cfg->error();
    #Read the value of the param in the file
    my $val = $cfg->param($pName);

    #Debug messages
    print  "Param is :: $val\n";

    return $val;
}

Print getPropInFile ('app.ini', 'trend');

Param app.ini文件:

[section 1]
trend=GoingUp
email=all
skip=no
active=true

输出:

DEBUG:: File Name  => app.ini
DEBUG:: Param Name => trend
Param is :: 

知道我做错了什么吗?

1 个答案:

答案 0 :(得分:1)

我现在不在我的机器上,但是快速查看文档会给我一个印象,你可能需要使用“section 1.trend”作为参数名称。

相关问题