如何提高Perl中lock_keys的使用率? [英] How to improve the usage of lock_keys in Perl?
本文介绍了如何提高Perl中lock_keys的使用率?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用 Hash :: Util
的 lock_keys
无论何时尝试访问不存在的键入一个散列。
-
有时候我的哈希值很深(散列哈希
哈希哈希...)。是否有
的快捷方法可以一次全部锁定它们? -
是否有可能在失败时控制
默认消息
添加找不到密钥的散列的转储)
解决方案
-
捕获异常,然后随意转储并重新抛出。
使用Try :: Tiny;
尝试{
$ hash {key} = 123; #非法修改
} catch {
使用DDS; DumpLex \%hash;
die $ _;
}
I'm using Hash::Util
's lock_keys
to die whenever trying to access a non-existing key in a hash.
Sometimes my hashes are deep (hash of hashes of hashes...). Is there a quick method to lock them all at once?
Is it possible to control the default message upon failure (i.e. add a Dump of the hash in which the key wasn't found)
解决方案
Catch the exception, then dump as you wish and rethrow.
use Try::Tiny;
try {
$hash{key} = 123; # illegal modification
} catch {
use DDS; DumpLex \%hash;
die $_;
}
这篇关于如何提高Perl中lock_keys的使用率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文