免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4688 | 回复: 5
打印 上一主题 下一主题

有人用过Config::INIFiles模块否,请教一下 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-11-13 21:08 |只看该作者 |倒序浏览
发现一个怪问题,Config::INIFiles里有个RewriteConfig, 在命令行下写个例子可以写ini文件,但是放到CGI里面就不能用了,返回值始终是undef

Cpan有个例子:
使用了下,好像好像也是不行,如下:
#!/usr/bin/perl

use Config::IniFiles;
use strict;
use CGI;
my ($prog,
    $cfg, $inifile, $form,
    $section, $param, $value, $name, $length,
        $row, @rows, $input,
    );
my $VERSION = qw($Revision: 1.4 $)[1];

# Configuration variables
$inifile = "configuration.ini"; # Hardcoded for security
$prog = "iniedit.cgi"; # The name of this file

my $cgi = new CGI;
my $cfg = Config::IniFiles->new(-file => $inifile);

if ($cgi->param('action') eq "change")        {
        MakeChanges($cgi, $cfg);
}

print $cgi->header;
print $cgi->start_html();
print "<table>";
print $cgi->start_form(-method=>'POST',
                       -action=>$prog);
print $cgi->hidden(-name=>'action',
                   -value=>'change');

for $section ($cfg->Sections)        {
        $row = $cgi->th({-colspan=>'2'}, $section);
        print $cgi->Tr($row);
        for $param        ($cfg->Parameters($section))        {
                $value = $cfg->val($section, $param);
                $name = $section . "___" . $param;
                $length = length($value) + 5;
                $input = $cgi->textfield(-name=>$name,
                                                -value=>$value,
                                                -size=>$length);
                $row = $cgi->td({-align=>'RIGHT'},$param) .
                       $cgi->td({-align=>'LEFT'},$input);
                print $cgi->Tr($row);
        } # End for param
} #  End for sections

$row = $cgi->td({-colspan=>'2'}, $cgi->submit('Make changes'));
print $cgi->Tr($row);
print "</form></table>";
print $cgi->end_html();

sub MakeChanges        {
        my ($cgi, $cfg) = @_;
        my ($key, $section, $param, @fields, $field);
       
        @fields = $cgi->param;
        for $field (@fields)        {
                if ($field =~ /___/)        {
                        ($section, $param) = split /___/, $field;
                        $cfg->setval($section, $param, $cgi->param($field));
                }
        }  #  End keys

        $cfg->RewriteConfig;
        $cfg->ReadConfig;
}  #  End sub MakeChanges

=head1 NAME

iniedit.cgi - Interface for editing a generic ini configuration
file from the web.

=head1 DESCRIPTION

Generates a HTML form containing the sections and values from a
.ini-style configuration file, and lets you modify them.

=head1 README

Generates a HTML form containing the sections and values from a
.ini-style configuration file, and lets you modify them.

=head1 PREREQUISITES

        C<Config::IniFiles>, C<CGI.pm>

=pod OSNAMES

Any

=pod SCRIPT CATEGORIES

CGI

=cut

论坛徽章:
0
2 [报告]
发表于 2010-11-13 21:08 |只看该作者
就是其中的:

        $cfg->RewriteConfig;
        $cfg->ReadConfig;

论坛徽章:
0
3 [报告]
发表于 2010-11-13 21:38 |只看该作者
cgi没试过··

论坛徽章:
0
4 [报告]
发表于 2010-11-15 14:45 |只看该作者
有些模块在特定环境的确可能不行
比如Switch模块在mod_perl环境也是无效的

论坛徽章:
0
5 [报告]
发表于 2010-11-18 09:24 |只看该作者
首先确认你的文件是你httpd用户权限可读的,再次看下你的系统路径中该文件是哪里
可以用./的方式试下或者用全路径来表示会更好

论坛徽章:
0
6 [报告]
发表于 2010-11-18 14:41 |只看该作者
确实不行的话··找一下其他的模块咯···或者楼主自己写一个···解析ini应该不难···
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP