my $EMPTY = q{}; use constant TRUE => ( 1==1 ); use constant FALSE => ( 1==2 ); my $a = ""; vs my $a = $EMPTY; my $b = 0; vs my $b = FALSE
应该使用哪种方法有什么区别?
这取决于某些情况吗?
如果是这样的话,那些关于你何时想要使用我的$b = 0的情况是什么;我的$b = FALSE,反之亦然?
解决方法
>“”和q {}都生成零长度字符串.
>perl -MDevel::Peek -e"$_ = q{}; Dump($_);" SV = PV(0x306748) at 0x4c9058 REFCNT = 1 FLAGS = (POK,pPOK) <--- Contains a string. PV = 0x4ac9e8 ""\0 CUR = 0 <--- Length of the string is zero. LEN = 16
> 0产生数字零.
>perl -MDevel::Peek -e"$_ = 0; Dump($_)" SV = IV(0x229088) at 0x229098 REFCNT = 1 FLAGS = (IOK,pIOK) <--- Contains a signed integer. IV = 0 <--- Contained integer is zero.
>(1 == 2)生成标量包含空字符串且数值为零.
>perl -MDevel::Peek -e"$_ = 1==2; Dump($_);" SV = PVNV(0x1fc598) at 0x259038 REFCNT = 1 FLAGS = (IOK,NOK,POK,pIOK,pNOK,pPOK) <--- A signed int,a float and a str. IV = 0 <--- Contained integer is zero. NV = 0 <--- Contained floating point number is zero. PV = 0x23ca18 ""\0 CUR = 0 <--- Length of the string is zero. LEN = 16
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。