修改了变量变量


Modified variable variables

$m = 'this_is_m';
$this_is_m = 'this_is_m_not_full :(';
$this_is_m_full = 'this_is_m_FULL!! :D';
print ${$m};

(嗨,第一:P)输出:

this_is_m_not full :(

知道如何使用 $m 输出this_is_m_FULL!! :D吗?

我已经尝试过的:

print $"{$m}_full";
print $'{$m}_full';
print $'$m_full';
print ${$m}_full';

没有一个奏效...提前感谢,

解决方案是:

print ${$m . '_full'};

但这感觉很黑客。

要获得所需的输出,您需要执行以下操作:

print ${$m . "_full"};

以下方法应该有效:

print ${$m.'_full'};

这是因为大括号内的字符串将首先被计算,成为

print ${'this_is_m' . '_full'}  
  ->  print ${'this_is_m_full'}  
  ->  print $this_is_m_full

如果您想了解更多信息,请查看此手册页。