[問題] eval for string

作者: sixth (衝向世界的最高峰)   2019-07-19 10:12:51
請問如何讓範例2 像 範例1 一樣,印出計算結果?
範例1:
eval '$sum = ((0x1 << 8) -1)';
print "The sum is $sum\n";
==> 會印出 255
範例2:
$str_test = "((0x1 << 8) -1)";
eval '$sum = $str_test';
print "The sum is $sum\n";
==> 會印出 (0x1 << 8) -1)

Links booklink

Contact Us: admin [ a t ] ucptt.com