我如何使散列键查找不区分大小写? [英] How can I make hash key lookup case-insensitive?
本文介绍了我如何使散列键查找不区分大小写?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
$ perl -e'%hash =(FOO = > 1); printf%s\\\
,(存在$ hash {foo})? 是:否;'
否
$ perl -e'%hash =(FOO => 1); printf%s\\\
,(存在$ hash {FOO})? 是:否;'
是
是否有设置可以更改为当前脚本?
解决方案
您将不得不使用并列散列。例如 Hash :: Case :: Preserve 。
Evidently hash keys are compared in a case-sensitive manner.
$ perl -e '%hash = ( FOO => 1 ); printf "%s\n", ( exists $hash{foo} ) ? "Yes" : "No";'
No
$ perl -e '%hash = ( FOO => 1 ); printf "%s\n", ( exists $hash{FOO} ) ? "Yes" : "No";'
Yes
Is there a setting to change that for the current script?
解决方案
You will have to use a tied hash. For example Hash::Case::Preserve.
这篇关于我如何使散列键查找不区分大小写?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文