Perl初始化值:“”vs q {}和0 vs(1 == 2)

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

相关文章

1. 如何去重 #!/usr/bin/perl use strict; my %hash; while(...
最近写了一个perl脚本,实现的功能是将表格中其中两列的数据...
表的数据字典格式如下:如果手动写MySQL建表语句,确认麻烦,...
巡检类工作经常会出具日报,最近在原有日报的基础上又新增了...
在实际生产环境中,常常需要从后台日志中截取报文,报文的形...
最近写的一个perl程序,通过关键词匹配统计其出现的频率,让...