Can Perl string interpolation perform any expression evaluation?

前端 未结 2 685
旧时难觅i
旧时难觅i 2020-12-08 04:25

related to question: How do I substitute with an evaluated expression in Perl?

In Perl, is there a way like in Ruby to do:

$a = 1;
print \"#{$a + 1}\         


        
2条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-08 04:45

    You can use the @{[ EXPRESSION ]} trick that Greg Hewgill mentioned.

    There's also the Interpolation module, which allows you to do arbitrary transformations on the values you're interpolating (like encode HTML entities) in addition to evaluating expressions.

提交回复
热议问题