Chinaunix
标题:
有人用过Config::INIFiles模块否,请教一下
[打印本页]
作者:
nathanisl
时间:
2010-11-13 21:08
标题:
有人用过Config::INIFiles模块否,请教一下
发现一个怪问题,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
作者:
nathanisl
时间:
2010-11-13 21:08
就是其中的:
$cfg->RewriteConfig;
$cfg->ReadConfig;
作者:
wfnh
时间:
2010-11-13 21:38
cgi没试过··
作者:
yiten
时间:
2010-11-15 14:45
有些模块在特定环境的确可能不行
比如Switch模块在mod_perl环境也是无效的
作者:
nsnake
时间:
2010-11-18 09:24
首先确认你的文件是你httpd用户权限可读的,再次看下你的系统路径中该文件是哪里
可以用./的方式试下或者用全路径来表示会更好
作者:
wfnh
时间:
2010-11-18 14:41
确实不行的话··找一下其他的模块咯···或者楼主自己写一个···解析ini应该不难···
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2