2009年1月2日星期五

[PerlChina] Re: Question about if (@array)

Ray 写道:
> 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
>
>
> >
>
>

1)反正是标量环境,你自己转换,或者perl帮你转换,应该没区别的。
2)delete可以操作标量吗?


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

没有评论: