2008年12月30日星期二

[PerlChina] Question about if (@array)

Hi, all

Would you explain the output of the following perl codes?

question 1:
Is the sentence "if (@array) " same as "if ( scalar(@array) )"??
question 2:
what's the difference of "undef $variable " and "delete $variable"??

Thanks,
Ray

-------------------------------------------
code----------------------------------
#!/usr/bin/perl

use strict;
use warnings;

my @host = ();
my @host1 = ('fdfd', 'fdfdfd');
my @host2 = undef;

if ( @host ) {
print "host ok\n";
} else {
print "host fail\n";
}

if ( @host1 ) {
print "host1 ok\n";
} else {
print "host1 fail\n";
}

if ( @host2 ) {
print "host2 ok\n";
} else {
print "host2 fail\n";
}
-------------------------------------------
code----------------------------------

and the output is :
host fail
host1 ok
host2 ok


--~--~---------~--~----~------------~-------~--~----~
您收到此信息是由于您订阅了 Google 论坛"PerlChina 论坛"论坛。
要在此论坛发帖,请发电子邮件到 perlchina@googlegroups.com
要退订此论坛,请发邮件至 perlchina+unsubscribe@googlegroups.com
更多选项,请通过 http://groups.google.com/group/perlchina?hl=zh-CN 访问该论坛
-~----------~----~----~----~------~----~------~--~---

没有评论: