Learning Perl: 2.11. The defined Function
来源:互联网 发布:京东和淘宝买吉他 编辑:程序博客网 时间:2024/05/22 10:42
2.11. The defined Function
One operator that can return undef is the line-input operator, <STDIN>. Normally, it returns a line of text. But if there is no more input, such as at end-of-file, it will return undef to signal this.[*] To tell if a value is undef and not the empty string, use the defined function, which returns false for undef and true for everything else:
[*] Normally, there's no "end-of-file" when the input comes from the keyboard, but the input may have been redirected to come from a file. Or the user may have pressed the key that the system recognizes to indicate end-of-file.
$madonna = <STDIN>; if ( defined($madonna) ) { print "The input was $madonna"; } else { print "No input available!/n"; }
If you'd like to make your own undef values, you can use the obscurely named undef operator:
$madonna = undef; # As if it had never been touched
- Learning Perl: 2.11. The defined Function
- Learning Perl: 9.3. The join Function
- Perl Learning: 2.6. The if Control Structure
- Learning Perl: 2.8. The chomp Operator
- Perl Learning: 2.9. The while Control Structure
- Perl Learning: 2.10. The undef Value
- Learning Perl: 3.6. The foreach Control Structure
- Learning Perl: 4.8. The use strict Pragma
- Learning Perl: 4.9. The return Operator
- Learning Perl: 5.3. The Invocation Arguments
- Learning Perl: 8.4. The Binding Operator, =~
- Learning Perl: 8.6. The Match Variables
- Learning Perl: 9.2. The split Operator
- Learning Perl: 10.1. The unless Control Structure
- Learning Perl: 10.2. The until Control Structure
- Learning Perl: 10.5. The elsif Clause
- Learning Perl
- Learning Perl
- C++ CFile::Rename 出现“拒绝访问”异常 及解决方案(不能说原创,自己悟出来的)
- JAVA的内省机制(introspector)与反射机制(reflection)
- 无电池的情况下,如何升级DELL INSPIRON 6400的bios
- Perl Learning: 2.9. The while Control Structure
- Perl Learning: 2.10. The undef Value
- Learning Perl: 2.11. The defined Function
- A
- CSS控制排版(转载)
- Learning Perl: 2.12. Exercises
- LINUX上安装memcached
- Java异常框架中finally执行、及其他相关问题
- Struts2开发知识点
- Ubuntu下交叉编译tslib-1.4记录
- Learning Perl: 3.1. Accessing Elements of an Array