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

有人可以解释为什么调用 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

https://stackoverflow.com/questions/14302487/

相关文章:

regex - Perl 正则表达式问题

php - 退出 php 命令而不触发关闭函数

python - 如何使用 GitPython 指定 Commit 的 committed_date

git - 无法将提交推送到 fork 的 repo

google-apps-script - 使用 google-apps-script 了解文件类型

regex - Clojure 正则表达式匹配

haskell - 与 GADT 的模式匹配

php - 使用递归将 html_entity_decode 应用于对象和数组

list - Scala 列表中的对象类型

php - 具有任意数量 URL 段的 Laravel 4 路由