2011年10月26日 星期三

Perl 使用constant注意不能expand常數

As with all use directives, defining a constant happens at compile time. Thus, it's probably not correct to put a constant declaration inside of a conditional statement (like if ($foo) { use constant ... } ).
Constants defined using this module cannot be interpolated into strings like variables. However, concatenation works just fine:
  1. print "Pi equals PI...\n"; # WRONG: does not expand "PI"
  2. print "Pi equals ".PI."...\n"; # right

沒有留言:

張貼留言