1
$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 :(

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

我已经尝试过的:

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

没有工作...在此先感谢,,

4

3 回答 3

2

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

print ${$m . "_full"};
于 2012-05-14T16:35:11.293 回答
2

解决方案是:

print ${$m . '_full'};

但这感觉非常hackish。

于 2012-05-14T16:35:12.253 回答
1

以下应该有效:

print ${$m.'_full'};

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

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

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

于 2012-05-14T16:48:05.277 回答