wordlist.pl第11行靠近“0”的perl语法错误$fh";
请帮忙wordlist.pl第11行靠近“0”的perl语法错误$fh";,perl,syntax,operator-keyword,scalar,Perl,Syntax,Operator Keyword,Scalar,请帮忙 Scalar found where operator expected at wordlist.pl line 8, near ") $fh" (Missing operator before $fh?) syntax error at wordlist.pl line 8, near ") $fh" Execution of wordlist.pl aborted due to compilation errors. 去掉这里的括号 第一个参数是filehandle
Scalar found where operator expected at wordlist.pl line 8, near ") $fh"
(Missing operator before $fh?)
syntax error at wordlist.pl line 8, near ") $fh"
Execution of wordlist.pl aborted due to compilation errors.
去掉这里的括号
第一个参数是filehandle,第二个参数是filename。您正在使用$fn
作为文件名和文件句柄,而$file
从未定义过
open ($fn), $file;
你不能像这样在一个街区周围留下大括号。我也不确定,$fh
应该是什么,因为你再也不用它了
您似乎对Perl的语法感到困惑。你是如何学习Perl的
去掉这里的括号
第一个参数是filehandle,第二个参数是filename。您正在使用$fn
作为文件名和文件句柄,而$file
从未定义过
open ($fn), $file;
你不能像这样在一个街区周围留下大括号。我也不确定,$fh
应该是什么,因为你再也不用它了
您似乎对Perl的语法感到困惑。您是如何学习Perl的?您可能混淆了文件名
$file
和文件句柄$fh
尝试将前三行更改为
if (! -e "$fh") $fh="STDIN";
my$file=“words.txt”;
如果(!-e$文件){
my$fh=*STDIN;
}否则{
打开我的$fh,可能您混淆了文件名$file
和文件句柄$fh
尝试将前三行更改为
if (! -e "$fh") $fh="STDIN";
my$file=“words.txt”;
如果(!-e$文件){
my$fh=*STDIN;
}否则{
打开我的$fh,您对open
的理解是不正确的。在三参数调用中使用它的现代方式通常是:
my $file= "words.txt";
if (! -e $file) {
my $fh = *STDIN;
} else {
open my $fh, '<', $file;
}
如果STDIN不存在,则只需使用特殊的菱形运算符
对其进行操作。您对打开的理解是不正确的。将其与三参数调用一起使用的现代方法通常是:
my $file= "words.txt";
if (! -e $file) {
my $fh = *STDIN;
} else {
open my $fh, '<', $file;
}
然后,如果STDIN不存在,只需使用特殊的菱形运算符
对其进行操作。Perl始终需要在条件后的代码周围加括号:
你写道:
my $file = 'words.txt';
if (! -e $file) {
print "$file does not exist\n";
}
else {
# open your file here and remember to close it
}
你应该写:
if (! -e "$fh") $fh="STDIN";
或:
这些代码在语法上是正确的。但是,代码在语义上是断断续续的。要打开文件,请使用:
$fh = "STDIN" if ! -e "$fh";
打开我的$fh,”Perl总是要求在以下条件后的代码周围加大括号:
你写道:
my $file = 'words.txt';
if (! -e $file) {
print "$file does not exist\n";
}
else {
# open your file here and remember to close it
}
你应该写:
if (! -e "$fh") $fh="STDIN";
或:
这些代码在语法上是正确的。但是,代码在语义上是断断续续的。要打开文件,请使用:
$fh = "STDIN" if ! -e "$fh";
打开我的$fh,'