我試圖讓哈希散列的鍵哈希散列的鍵,總是有錯誤:獲取
use strict;
my %oop_hash =();
$oop_hash{'wfh'}{'ppb'} = "451103";
print (keys $oop_hash{'wfh'})."\n"; #1st try
print (keys %oop_hash{'wfh'})."\n"; #2nd try
我怎樣才能哈希散列的鑰匙?
我試圖讓哈希散列的鍵哈希散列的鍵,總是有錯誤:獲取
use strict;
my %oop_hash =();
$oop_hash{'wfh'}{'ppb'} = "451103";
print (keys $oop_hash{'wfh'})."\n"; #1st try
print (keys %oop_hash{'wfh'})."\n"; #2nd try
我怎樣才能哈希散列的鑰匙?
這是一個有點棘手。正確的語法是
keys %{$oop_hash{'wfh'}}
此外,正如你所寫的,你的print statement will not quite do what you want。由於Perl解析該行的方式,"\n"
不會附加到該字符串。你必須說:
print +(keys %{$oop_hash{'wfh'}}),"\n";
print ((keys %{$oop_hash{'wfh'}}),"\n");
添加'使用警告',你會發現它有什麼問題。 – varnie 2013-03-19 14:56:37
使用Perl 5.14或更高版本,您的第一個版本可以正常工作。 – 2013-03-19 16:30:50