所有使用的密鑰應該出現在初始%哈希定義中。如果散列鍵在初始散列定義中沒有定義,是否有辦法讓perl編譯失敗?
use strict;
my %hash = ('key1' => 'abcd', 'key2' => 'efgh');
$hash{'key3'} = '1234'; ## <== I'd like for these to fail at compilation.
$hash{'key4'}; ## <== I'd like for these to fail at compilation.
有沒有辦法做到這一點?
有一種叫做類的東西。你可能需要這個。 –
您可以批准答案的時間。 – DavidO