我正在尝试读取哈希值,其名称和索引存储在字符串中。如果我对哈希及其索引进行硬编码,我只能获得该值,但如果我从另一个变量中获取它则不能。为了更好地描述它,我提到了下面的代码:
use strict 'vars';
#------------------------------
# Hash to store some values
our %SystemUser = (
Username => "system",
Password => "system"
);
# Prints successfully if i use the below technique
print "Using Hard-Coding technique : ${SystemUser{'Password'}}\n";
my $Reference = "SystemUser{'Password'}";
# Doesn't print if i use this technique where $Reference contains the hash-index pair
print "Using Referencing technique : ${$Reference}\n";
print "Reference value : $Reference\n";
我想打印SystemUser{'Password'}
使用的价值${$Reference}
($Reference = "SystemUser{'Password'}"
有价值)