读 《C程序员精通Perl》http://book.douban.com/subject/1232075/ 2.4节 笔记
#!/usr/bin/perl
use strict;
use warnings;
if ( "19" < "100") { #true 数字比较
print "19 < 100\n";
}
if ( "19" le "100") { #false 字符串比较
print "19 le 100\n";
}
if ("hello" eq "world") { #false 字符串比较
print "hello eq world\n";
}
if ("able" == "baker") { #true 数字比较, 但发出告警
print "able == baker\n";
}
运行结果:
[root@localhost perl_practice]# ./cond.pl
19 < 100
Argument "world" isn't numeric in numeric eq (==) at ./cond.pl line 18.
Argument "hello" isn't numeric in numeric eq (==) at ./cond.pl line 18.
able == baker
[root@localhost perl_practice]#
本文详细解析了Perl编程中条件语句的使用方法,包括数字和字符串比较,以及遇到非数值类型时的错误提示。通过实例演示了如何正确地进行比较操作,并在遇到类型不匹配时进行有效的错误处理。
981

被折叠的 条评论
为什么被折叠?



