gpt4 book ai didi

perl - 调用 ref 没有返回任何东西

转载 作者:行者123 更新时间:2023-12-05 08:34:57 25 4
gpt4 key购买 nike

有人可以解释为什么调用 ref 没有返回任何东西吗?

[pista@HP-PC ~]$ perl -wlae '$var=1; print ref($var)'

[pista@HP-PC ~]$ perl -wlae '@var=1; print ref(@var)'

[pista@HP-PC ~]$ perl -v

This is perl 5, version 14, subversion 3 (v5.14.3) built for x86_64-linux-thread-multi

Copyright 1987-2012, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl". If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.

[pista@HP-PC ~]$ uname -a
Linux HP-PC 3.6.11-1.fc16.x86_64 #1 SMP Mon Dec 17 21:29:15 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux

我做错了什么?

最佳答案

来自 perldoc -f ref :

ref EXPR
ref Returns a non-empty string if EXPR is a reference, the empty
string otherwise.

您的值是一个标量和一个数组,它们不是引用,因此 ref 返回空字符串。如果你要这样做:

print ref \$var;

你会得到输出:SCALAR

关于perl - 调用 ref 没有返回任何东西,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14302487/

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