【发布时间】:2015-12-02 20:28:45
【问题描述】:
考虑以下 Perl 程序。
use strict;
use warnings;
my @foo = qw(a b c);
undef = shift @foo;
print scalar @foo;
这将终止并显示错误消息:
尝试修改只读值...
使用 const 会给出不同的错误:
1 = shift @foo;
无法在...处修改标量赋值中的常量项
... 由于编译错误而中止执行。
如果我们这样做也一样:
(1) = shift @foo;
所有这些对我来说都很有意义。但是将undef 放入列表中会起作用。
(undef) = shift @foo;
现在它打印2。
当然,如果您有一堆返回值并且只需要特定的返回值,这是常见的做法,就像这里:
my (undef, undef ,$mode, undef ,$uid, $gid, undef ,$size) = stat($filename);
perldoc -f undef 中的第 9 行代码示例显示了这一点,但没有解释。
我的问题是,Perl 内部是如何处理的?
【问题讨论】:
标签: perl