Perl 语言中的关于 !=与 ne 在程序中的问题
sc0or 2008-10-30 07:01:26 sub total{
my $count;
if (@_ != undef) { #when use NE to replace !=, you will got the different result, why ?
foreach (@_) {
$count += $_;
}
$count;
} else {
0;
}
}
my $sum1 = &total();
print $sum1;
我的问题就是,当我分别用 ne 和 != 时,程序会输出不同的结果。
当你用 !=,程序会按照我的意思在屏幕上输出 0。
当你用 ne,程序会输出到屏幕上是空(没结果),我希望是输出0。为什么啊?我刚刚学习Perl。
第二:
sub total{
my $count;
if (@_ != undef) {
foreach (@_) {
$count += $_;
}
$count;
} else {
print "The number is undef or none" #为什么我这样写会编译不过去?
0;
}
}
my $sum1 = &total();
我希望是先输出这句话The number is undef or none,然后返回 0 给sum1