Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.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
wordlist.pl第11行靠近“0”的perl语法错误$fh";_Perl_Syntax_Operator Keyword_Scalar - Fatal编程技术网

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,'