2012-05-14 46 views
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'; 

无提前工作...谢谢,,

+0

你考虑过使用数组吗? – jeroen

+1

如果你必须使用变量变量,你有一些主要的设计缺陷... –

回答

2

解决的办法是:

print ${$m . '_full'}; 

但是这感觉非常黑客。

+0

THANKs ...作品! – malik51

+0

这是“hackish”哈哈,但我正在寻找“优化”; ) – malik51

2

为了让您所需的输出,你需要做到以下几点:

print ${$m . "_full"}; 
+0

谢谢! – malik51

1

下面应该工作:

print ${$m.'_full'}; 

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

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

如果你想要更多这方面的信息,看看this manual page

+0

谢谢..我现在全部排序了......我会再读一遍! – malik51