0

我对 Perl 很陌生,目前正在关注 youtube 教程指南(https://www.youtube.com/watch?v=WEghIXs8F6c)。首先,他解释了使用 print 打印变量的语法,然后在视频中大约 8 点 50 分,他解释了如何有另一种打印方法,称为“say”。但是,此时当我尝试完全运行此代码时,我收到以下弹出消息:

你好世界!在 Hello_world.pl 第 21 行 (#1) (F) 仅允许硬引用由“严格 refs” 使用字符串(“curt living on “123 main st””)作为符号 ref ”。不允许使用符号引用。见 perlref。用户代码中未捕获的异常:在 Hello_world.pl 第 21 行使用“strict refs”时,不能使用字符串(“curt 生活在“123 main st”上)作为符号引用。在 Hello_world.pl 第 21 行按任意键接着说 。. .

作为序言,这是我到目前为止使用的代码行:

#!/usr/bin/perl

use strict;
use warnings;
use diagnostics;
use feature 'say';
use feature "switch";
use v5.12.3;
print " Hello World!\n";
my $name = 'curt';
my ($age, $street) = (40, '123 main st');
my $my_info = "$name lives on \"$street\"\n";
print $my_info
my $bunch_of_info = <<"END";
This is 
a lot of information
for different lines
END
say $bunch_of_info

我感谢任何和所有的帮助。非常感谢您提前。

4

2 回答 2

2

你有

print $my_info
my $bunch_of_info = ...;

缺少的分号表示$my_info预计是文件句柄。

print $fh ...;

文件句柄可以是对包含文件句柄的 glob 的引用。该字符串123 main st在技术上是有效的参考,除非strict refs启用了限制(特别是 )。因此,你得到了你得到的错误。

于 2021-06-13T04:19:32.103 回答
-1

请查看更正的代码并与您的代码进行比较

#!/usr/bin/env perl

use strict;
use warnings;
use diagnostics;
use feature 'say';
use feature "switch";
use v5.12.3;

print " Hello World!\n";

my $name = 'curt';
my ($age, $street) = (40, '123 main st');
my $my_info = "$name lives on \"$street\"\n";

print $my_info;

my $bunch_of_info = <<"END";
This is
a lot of information
for different lines
END

say $bunch_of_info;

输出

 Hello World!
curt lives on "123 main st"
This is
a lot of information
for different lines
于 2021-06-13T01:17:32.510 回答