Constant Folding

Constant Folding

Like C, Perl does a certain amount of expression evaluation at compile time whenever it determines that all arguments to an operator are static and have no side effects. In particular, string concatenation happens at compile time between literals that don't do variable substitution. Backslash interpolation also happens at compile time. You can say

  'Now is the time for all'
. "\n" 
.  'good men to come to.'

and this all reduces to one string internally. Likewise, if you say

   foreach $file (@filenames) {
if (-s $file > 5 + 100 * 2**16) {  }
   }

the compiler precomputes the number which that expression represents so that the interpreter won't have to.

doc_perl
2016-12-06 03:18:47
Comments
Leave a Comment

Please login to continue.