无法在perl CGI中打印文件的内容

时间:2013-06-05 06:53:38

标签: perl file cgi file-handling

我想在网页中逐行打印文件内容 这是我拒绝工作的代码。

open(CNF, '<G:\automation_managment\".$n."\config.txt') or die "cant open";
my @cnf=<CNF>;
close(CNF);
my $i= 0;
print "your city, $cnf[$i]"; 
$i++;
print "your age, $cnf[$i]"; 
$i++;
print "your grade, $cnf[$i]"; 
$i++;
print "your phone number, $cnf[$i]"; 
$i++;
print "your email id, $cnf[$i]";

打开命令有错误吗? 它与绝对路径一起工作正常。但不是路径中的变量

1 个答案:

答案 0 :(得分:1)

更改此行:

open(CNF, '<G:\automation_managment\".$n."\config.txt') or die "cant open";

由:

open(CNF, '<G:\automation_managment\'.$n.'\config.txt') or die "cant open";

请注意单引号而不是双引号。

此外,您可以使用正斜杠而不是向后斜杠:

open(my $fh, '<', 'G:/automation_managment/'.$n.'/config.txt') or die "cant open"
相关问题