【发布时间】:2015-10-31 05:18:05
【问题描述】:
因此,在 Strawberry Perl 中,%ENV 似乎是一个普通的哈希(至少它没有绑定), 但它似乎也可以不区分大小写地解析键。鉴于这种环境,这是有道理的 PowerShell 中的变量不区分大小写(我不确定 Windows 环境变量和大小写)。所以,我想知道 %ENV 如何同时成为 普通哈希,并且具有“隐式”键,当您称它们为内置键时,这些键未列出。 %ENV 哈希是不是很神奇而不被绑定?
use strict;
use warnings;
# Env appears to be an ordinary hash
# 'TEMP' is present in the list of environment variables
# but 'temp' is not
printf "$_\n" foreach keys %ENV;
print "\n";
# this gives us the value of $ENV:TEMP
# which makes sense.
printf "uppercase 'temp' maps to %s\n", $ENV{TEMP};
# even though temp is not present in the
# list of keys, the same value appears as for
# $ENV{TEMP}
# This seems to make sense given the behavior of powershell
# (I am not quite sure what the relationship is between
# Windows environment variables and case, but this seems reasonable.)
printf "lowercase 'temp' maps to %s\n", $ENV{temp};
# However, %ENV is not a tied hash.
printf "Tie status: %s\n", tied(%ENV) // "not a tied variable";
【问题讨论】:
标签: windows perl environment-variables strawberry-perl