#!/usr/bin/perl -w
use strict;
my $var = undef;
if($var > 0){
print "> 0\n";
}
elsif($var == 0){
print "== 0\n";
}
else{
print "< 0";
}
執行結果如下:
[running]test@localhost:/usr/local/app$ perl p.pl
Use of uninitialized value in numeric gt (>) at p.pl line 5.
Use of uninitialized value in numeric eq (==) at p.pl line 5.
== 0
顯然,在進行數據比較時,undef會被默認轉換爲數字0進行比較。