2012-05-14 45 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