所有使用的密钥应该出现在初始%哈希定义中。如果散列键在初始散列定义中没有定义,是否有办法让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