- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我如何确定一个 perl 函数返回 nothing
甚至 undef
?
例子:
sub test {
return;
}
或
sub test {}
问题是好奇的代理函数也可以返回字符串、列表……并且是外部包的一部分。所以我无法用 test() || 检查undef
因为空列表或字符串将被 undef
覆盖。
有谁知道如何检查“null”值,以便创建条件异常?
最佳答案
If you use
return
and you specify no return value, the subroutine returns an empty list in list context, the undefined value in scalar context, or nothing in void context.If no
return
is found and if the last statement is an expression, its value is returned. If the last statement is a loop control structure like aforeach
or awhile
, the returned value is unspecified. The empty sub returns the empty list.
- perlsub
在这两种情况下,它都会返回空列表。所以你无法区分它们。
如果我对你的理解是正确的,那么当你执行 test () || 时,你正在尝试避免空列表被 undef 覆盖未定义
。但这没关系。在 Perl 中,空列表和 undef 都被认为是错误的。
下面所有的都是假的
0
'0'
undef
'' # Empty scalar
() # Empty list
('')
关于perl - 我如何检查子例程是否返回 *nothing*,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39872477/
我最近购买了《C 编程语言》并尝试了 Ex 1-8这是代码 #include #include #include /* * */ int main() { int nl,nt,nb;
早上好!我有一个变量“var”,可能为 0。我检查该变量是否为空,如果不是,我将该变量保存在 php session 中,然后调用另一个页面。在这个新页面中,我检查我创建的 session 是否为空,
我正在努力完成 Learn Python the Hard Way ex.25,但我无法理解某些事情。这是脚本: def break_words(stuff): """this functio
我是一名优秀的程序员,十分优秀!