显然,哈希密钥以区分大小写的方式进行比较.
$ 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
Run Code Online (Sandbox Code Playgroud)
是否有更改当前脚本的设置?
my %hash = (FOO => 1);
my $key = 'fOo'; # or 'foo' for that matter
my %lookup = map {(lc $_, $hash{$_})} keys %hash;
printf "%s\n", ( exists $hash{(lc $key)} ) ? "Yes" : "No";
Run Code Online (Sandbox Code Playgroud)