gpt4 book ai didi

perl - 与我在 perl 中的变量混淆

转载 作者:行者123 更新时间:2023-12-04 10:25:54 26 4
gpt4 key购买 nike

如果使用 use strictuse warning
如果我指定 my数据类型,它有效;如果我不指定 my它说错误。

use strict;
use warnings;
my $test=10;
my @arr=(10,20,30);

如果我将数组变量名称声明为数字:
 use strict;
use warnings;
my @100=(10,20,30);

然后当我运行该程序时,它说错误:
 Can't use global @100 in "my" at number_sclar.pl line 28, near "my @100"

如果我删除了 my并运行该程序,它运行没有错误。

所以请谁能告诉我为什么 my数字数组变量名称不支持变量?

最佳答案

来自 perldoc perlvar :

Perl identifiers that begin with digits, control characters, or punctuation characters are exempt from the effects of the "package" declaration and are always forced to be in package "main"; they are also exempt from "strict 'vars'" errors. A few other names are also exempt in these ways...

关于perl - 与我在 perl 中的变量混淆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16579528/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com