Perl错误:打开文件时参数无效
我是perl新手。我试图执行下面提到的程序: 我正试图打开一个文件并从文件中读取内容Perl错误:打开文件时参数无效,perl,Perl,我是perl新手。我试图执行下面提到的程序: 我正试图打开一个文件并从文件中读取内容 $FILE=open(FILE,"\\10.82.71.28\Testing501\Test_Folder\834_KMS_FACE_834A.mms"); if($FILE) { print "The file: $FILE has opened successfully"; } else { die "There is an error while opening the file :
$FILE=open(FILE,"\\10.82.71.28\Testing501\Test_Folder\834_KMS_FACE_834A.mms");
if($FILE)
{
print "The file: $FILE has opened successfully";
}
else
{
die "There is an error while opening the file :$!\n";
}
while($record=<FILE>)
{
print $record;
}
close(FILE);
$FILE=open(文件“\\10.82.71.28\Testing501\Test_Folder\834_KMS_FACE_834A.mms”);
如果($FILE)
{
打印“文件:$file已成功打开”;
}
其他的
{
die“打开文件时出错:$!\n”;
}
而($record=)
{
打印$记录;
}
关闭(文件);
但在执行程序时,我遇到了一个错误:
打开文件时出错:参数无效请尝试:
open my $file, '<', 'path' or die "path: $!"
while($record = <$file>) ...
打开我的$file,”试试:
打开我的$file,”如果执行
print "\\10.82.71.28\Testing501\Test_Folder\834_KMS_FACE_834A.mms";
你得到
Unrecognized escape \T passed through at a.pl line 1.
Unrecognized escape \T passed through at a.pl line 1.
Unrecognized escape \8 passed through at a.pl line 1.
\10.82.71.28Testing501Test_Folder834_KMS_FACE_834A.mms
(您确实使用了使用严格;使用警告;
,对吗?)
您希望代码生成以下字符串:
\\10.82.71.28\Testing501\Test_Folder\834_KMS_FACE_834A.mms
正如您在上面所看到的,以下内容显然无法生成所需的字符串:
"\\10.82.71.28\Testing501\Test_Folder\834_KMS_FACE_834A.mms"
您可以使用以下选项:
"\\\\10.82.71.28\\Testing501\\Test_Folder\\834_KMS_FACE_834A.mms"
如果你执行
print "\\10.82.71.28\Testing501\Test_Folder\834_KMS_FACE_834A.mms";
你得到
Unrecognized escape \T passed through at a.pl line 1.
Unrecognized escape \T passed through at a.pl line 1.
Unrecognized escape \8 passed through at a.pl line 1.
\10.82.71.28Testing501Test_Folder834_KMS_FACE_834A.mms
(您确实使用了使用严格;使用警告;
,对吗?)
您希望代码生成以下字符串:
\\10.82.71.28\Testing501\Test_Folder\834_KMS_FACE_834A.mms
正如您在上面所看到的,以下内容显然无法生成所需的字符串:
"\\10.82.71.28\Testing501\Test_Folder\834_KMS_FACE_834A.mms"
您可以使用以下选项:
"\\\\10.82.71.28\\Testing501\\Test_Folder\\834_KMS_FACE_834A.mms"
使用q
literal像这样转义反斜杠
$filepath = q{\\\10.82.71.28\Testing501\Test_Folder\834_KMS_FACE_834A.mms};
open my $FILE, '<', "$filepath" or die "path: $!"
while($record = <$FILE>) {
---
}
$filepath=q{\\\ 10.82.71.28\Testing501\Test\u Folder\834\u KMS\u FACE\u 834A.mms};
打开我的$FILE,使用q
literal像这样转义反斜杠
$filepath = q{\\\10.82.71.28\Testing501\Test_Folder\834_KMS_FACE_834A.mms};
open my $FILE, '<', "$filepath" or die "path: $!"
while($record = <$FILE>) {
---
}
$filepath=q{\\\ 10.82.71.28\Testing501\Test\u Folder\834\u KMS\u FACE\u 834A.mms};
打开我的$FILE,“您已经接受了答案,但是您可以始终使用正斜杠而不是反斜杠
$FILE=open(FILE,"//10.82.71.28/Testing501/Test_Folder/834_KMS_FACE_834A.mms");
顺便说一下,标准的Perl方法是使用或:
open(FILE,"//10.82.71.28/Testing501/Test_Folder/834_KMS_FACE_834A.mms")
or die qq(...);
而且,最好使用三参数形式,并为文件句柄使用标量变量。这样可以更容易地将文件作为子例程参数传递:
my $file_name = '//10.82.71.28/Testing501/Test_Folder/834_KMS_FACE_834A.mms';
open my $fh, "<", $file_name
or die qq(Couldn't open the file $file_name);
my$file_name='/10.82.71.28/Testing501/Test_Folder/834_KMS_FACE_834A.mms';
打开我的$fh,“您已经接受了答案,但您可以始终使用正斜杠而不是反斜杠
$FILE=open(FILE,"//10.82.71.28/Testing501/Test_Folder/834_KMS_FACE_834A.mms");
顺便说一下,标准的Perl方法是使用或:
open(FILE,"//10.82.71.28/Testing501/Test_Folder/834_KMS_FACE_834A.mms")
or die qq(...);
而且,最好使用三参数形式,并为文件句柄使用标量变量。这样可以更容易地将文件作为子例程参数传递:
my $file_name = '//10.82.71.28/Testing501/Test_Folder/834_KMS_FACE_834A.mms';
open my $fh, "<", $file_name
or die qq(Couldn't open the file $file_name);
my$file_name='/10.82.71.28/Testing501/Test_Folder/834_KMS_FACE_834A.mms';
打开我的$fh,“当git.exe使用该文件时,我遇到了这个错误。
它可能真的被变相拒绝访问。我在git.exe使用该文件时遇到了这个错误。
它可以伪装成拒绝访问。为什么每个人都使用双引号?\\10.82.71.28\Testing501\Test\u Folder\834\u KMS\u FACE\u 834A.mms'
有什么问题?@reinierpost,因为它错了?至少,您需要'\\\10.82.71.28\Te…'
,尽管我会使用'\\\\10.82.71.28\\Te…'
来避免您刚才犯的错误。@reinierpost,如果您害怕反斜杠,您可以使用'//10.82.71.28/Te…'
。Windows平等地接受两个斜杠。嗯。。。的确我被纠正了。。。即使在单引号字符串中,``也很特别。@reinierpost,是的,为了允许“不能”
为什么每个人都使用双引号?\\10.82.71.28\Testing501\Test\u Folder\834\u KMS\u FACE\u 834A.mms'
有什么问题?@reinierpost,因为它错了?至少,您需要'\\\10.82.71.28\Te…'
,尽管我会使用'\\\\10.82.71.28\\Te…'
来避免您刚才犯的错误。@reinierpost,如果您害怕反斜杠,您可以使用'//10.82.71.28/Te…'
。Windows平等地接受两个斜杠。嗯。。。的确我被纠正了。。。即使在单引号字符串中,``也很特殊。@reinierpost,是的,允许'can't'