终端给出错误而不是 运行 perl 脚本?
Terminal giving errors instead of running perl script?
我知道这是一个模糊的问题,但我不确定错误的性质是什么。我正在尝试学习 perl,但是当我尝试打开目录中的 perl 脚本时,它给了我很多错误并且拒绝打开它。但是这些都是我从例子里copy过来的脚本,不知道怎么会有这么多问题
这些是一个脚本的错误消息:
syntax error at atom1perl.pl line 11, near "my "
Global symbol "$name" requires explicit package name (did you forget to declare "my $name"?) at atom1perl.pl line 11.
syntax error at atom1perl.pl line 15, near ")
my "
Global symbol "$my_info" requires explicit package name (did you forget to declare "my $my_info"?) at atom1perl.pl line 15.
Global symbol "$my_info" requires explicit package name (did you forget to declare "my $my_info"?) at atom1perl.pl line 17.
Execution of atom1perl.pl aborted due to compilation errors (#1)
(F) Probably means you had a syntax error. Common reasons include:
A keyword is misspelled.
A semicolon is missing.
A comma is missing.
An opening or closing parenthesis is missing.
An opening or closing brace is missing.
A closing quote is missing.
Often there will be another error message associated with the syntax
error giving more information. (Sometimes it helps to turn on -w.)
The error message itself often tells you where it was in the line when
it decided to give up. Sometimes the actual error is several tokens
before this, because Perl is good at understanding random input.
Occasionally the line number may be misleading, and once in a blue moon
the only way to figure out what's triggering the error is to call
perl -c repeatedly, chopping away half the program each time to see
if the error went away. Sort of the cybernetic version of 20 questions.
Uncaught exception from user code:
syntax error at atom1perl.pl line 11, near "my "
Global symbol "$name" requires explicit package name (did you forget to declare "my $name"?) at atom1perl.pl line 11.
syntax error at atom1perl.pl line 15, near ")
my "
Global symbol "$my_info" requires explicit package name (did you forget to declare "my $my_info"?) at atom1perl.pl line 15.
Global symbol "$my_info" requires explicit package name (did you forget to declare "my $my_info"?) at atom1perl.pl line 17.
Execution of atom1perl.pl aborted due to compilation errors.
这是脚本:
use strict;
use warnings;
use diagnostics;
use feature 'say';
use feature "switch";
print "Hello World\n"
my $name = "X";
my ($age, $street) = (50, "XYZ")
my $my_info = "$name lives on \"$street\"n";
print $my_info
其他示例脚本也是如此。我认为问题出在我打开它的方式上,但我不知道任何其他方式。
请将更正后的代码与您拥有的代码进行比较。
use strict;
use warnings;
use diagnostics;
use feature 'say';
use feature 'switch';
print "Hello World\n";
my $name = "X";
my ($age, $street) = (50, "XYZ");
my $my_info = "$name lives on \"$street\"\n";
print $my_info;
输出
Hello World
X lives on "XYZ"
我知道这是一个模糊的问题,但我不确定错误的性质是什么。我正在尝试学习 perl,但是当我尝试打开目录中的 perl 脚本时,它给了我很多错误并且拒绝打开它。但是这些都是我从例子里copy过来的脚本,不知道怎么会有这么多问题
这些是一个脚本的错误消息:
syntax error at atom1perl.pl line 11, near "my " Global symbol "$name" requires explicit package name (did you forget to declare "my $name"?) at atom1perl.pl line 11. syntax error at atom1perl.pl line 15, near ")
my " Global symbol "$my_info" requires explicit package name (did you forget to declare "my $my_info"?) at atom1perl.pl line 15. Global symbol "$my_info" requires explicit package name (did you forget to declare "my $my_info"?) at atom1perl.pl line 17. Execution of atom1perl.pl aborted due to compilation errors (#1) (F) Probably means you had a syntax error. Common reasons include:
A keyword is misspelled. A semicolon is missing. A comma is missing. An opening or closing parenthesis is missing. An opening or closing brace is missing. A closing quote is missing.
Often there will be another error message associated with the syntax error giving more information. (Sometimes it helps to turn on -w.) The error message itself often tells you where it was in the line when it decided to give up. Sometimes the actual error is several tokens before this, because Perl is good at understanding random input. Occasionally the line number may be misleading, and once in a blue moon the only way to figure out what's triggering the error is to call perl -c repeatedly, chopping away half the program each time to see if the error went away. Sort of the cybernetic version of 20 questions.
Uncaught exception from user code: syntax error at atom1perl.pl line 11, near "my " Global symbol "$name" requires explicit package name (did you forget to declare "my $name"?) at atom1perl.pl line 11. syntax error at atom1perl.pl line 15, near ")
my " Global symbol "$my_info" requires explicit package name (did you forget to declare "my $my_info"?) at atom1perl.pl line 15. Global symbol "$my_info" requires explicit package name (did you forget to declare "my $my_info"?) at atom1perl.pl line 17. Execution of atom1perl.pl aborted due to compilation errors.
这是脚本:
use strict;
use warnings;
use diagnostics;
use feature 'say';
use feature "switch";
print "Hello World\n"
my $name = "X";
my ($age, $street) = (50, "XYZ")
my $my_info = "$name lives on \"$street\"n";
print $my_info
其他示例脚本也是如此。我认为问题出在我打开它的方式上,但我不知道任何其他方式。
请将更正后的代码与您拥有的代码进行比较。
use strict;
use warnings;
use diagnostics;
use feature 'say';
use feature 'switch';
print "Hello World\n";
my $name = "X";
my ($age, $street) = (50, "XYZ");
my $my_info = "$name lives on \"$street\"\n";
print $my_info;
输出
Hello World
X lives on "XYZ"