Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 7中ActivePerl的路径不起作用_Windows_Perl_Path - Fatal编程技术网

Windows 7中ActivePerl的路径不起作用

Windows 7中ActivePerl的路径不起作用,windows,perl,path,Windows,Perl,Path,我已在Windows 7计算机上安装。一切正常,但它无法从给定路径读取配置文件。我使用的代码是 use constant CONFIG_FNAME => '/windows/system32/softwareconfig.txt'; $self->{"config"} = &read_config_file($CONFIG_FNAME); warn "read_config_file(CONFIG_FNAME) returned undef" if !defined($sel

我已在Windows 7计算机上安装。一切正常,但它无法从给定路径读取配置文件。我使用的代码是

use constant CONFIG_FNAME => '/windows/system32/softwareconfig.txt';
$self->{"config"} = &read_config_file($CONFIG_FNAME);
warn "read_config_file(CONFIG_FNAME) returned undef" if !defined($self->{"config"});
它总是返回警告。如果我在同一个目录中使用
softwareconfig.txt
CONFIG\u FNAME=>“softwareconfig.txt”
,它就可以工作

这段代码在WindowsXP上运行得非常好。我也试着沿着这条路走,但似乎都不管用。这些都可以在WindowsXP中完美工作

CONFIG_FNAME => 'c:/windows/system32/softwareconfig.txt'
CONFIG_FNAME => 'c:\\windows\system32\softwareconfig.txt'
CONFIG_FNAME => 'c:\\windows\\system32\\softwareconfig.txt'
CONFIG_FNAME => "c:\\windows\\system32\\softwareconfig.txt"
CONFIG_FNAME => '\\windows\\system32\\softwareconfig.txt'

如何纠正此问题?

请始终使用严格的
在所有脚本的开头使用警告。它说:

变量“$CONFIG_FNAME”未在test1.pl第7行导入。 (您是指&CONFIG_FNAME吗?)

这两行必须是:

self->{"config"} = read_config_file(CONFIG_FNAME);
warn "read_config_file(".CONFIG_FNAME.") returned undef" if !defined($self->{"config"});

常数是一个简单的词。常量不能在引号内插入。

您的问题可能与Perl无关
Windows\system32
是一个受保护的系统目录,Vista和更高版本对该位置具有相当大的保护作用

我不认为文件名
'softwareconfig.txt'
是标准的Windows文件。如果要将自己的配置文件放在受保护的系统目录中,请停止这样做

提供Windows上特殊文件夹的列表


如果配置文件针对特定用户,则
ApplicationData
下的子目录是合适的。如果它适用于所有用户,那么在
CommonApplicationData
下的子目录是合适的。您可以只使用一个正斜杠。Perl会自动替换它。因此,如果试图访问该文件的服务或程序具有从该路径读取的权限,则
/windows/system32/softwareconfig.txt
将起作用


我的建议是:尝试将配置文件的权限更改为允许来自所有人。

可以肯定的是,不需要在路径上使用反斜杠。只需使用正斜杠。Perl会自动替换它。不需要在单引号字符串中转义反斜杠转义反斜杠在双引号中。我犯了输入错误,并在原来的问题中进行了更正。@hexerei软件,Perl不执行任何替换。Windows本机接受
\
/
作为路径分隔符。@Prabhu,
'c:\\Windows\\system32\\softwareconfig.txt'
“c:\\Windows\\system32\\softwareconfig.txt”
生成相同的字符串。@ikegami这就是我所说的“只需使用正斜杠。Perl自动替换它”因此,如果我在读取配置文件()之前删除了相应的权限,那么
/windows/system32/test.txt
本可以工作,但问题仍然存在。同样的代码在装有activeperl 8.10的XP机器上运行良好。@Prabhu:奇怪,它对我来说运行良好。您是否在
CONFIG\u FNAME
之前删除了
$
?可能是
read\u config\u file
产生错误?是的,$before config\u FNAME是一个键入错误。我已经在我的问题中更正了它。我将配置文件重新定位到
'd:\softwareconfig.txt'
,现在它正在工作。我认为问题是由于windows对系统文件夹的访问限制。您应该将文件放在用户目录中,或者像Sinan建议的那样放在应用程序数据目录中