perl的解引用问题
请教下,你能把KEY1的值打印出来吗,就是通过解引用hashref 打印出 VAL1
%$hashref = (KEY => "RING", BIRD => "SING");
$$hashref{KEY} = "VALUE";
print $$hashref{"KEY"}, " ", $$hashref{BIRD};
@$hashref{"KEY1", "KEY2"} = {"VAL1", "VAL2"};
[解决办法]
print("$$hashref{KEY1}->{VAL1}\n");
print("${$$hashref{KEY1}}{VAL1}\n");
都行,不过"@$hashref{"KEY1", "KEY2"} = {"VAL1", "VAL2"}"是个hash切片,
你这样等于只有KEY1有值,而VAL1是键,VAL2成了它的值
@$hashref{"KEY1", "KEY2"} = ("VAL1", "VAL2")你想要的是这个吧?