加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

windows – 草莓Perl是%ENV一个普通的对象

发布时间:2020-12-14 05:44:58 所属栏目:Windows 来源:网络整理
导读:所以,在Strawberry Perl中,%ENV似乎是一个普通的哈希(至少它没有绑定), 但它似乎也解决了密钥不敏感的问题.鉴于环境,这是有道理的 变量在Power Shell中不区分大小写(我不确定它们之间的确切关系 Windows环境变量和案例).所以,我想知道%ENV如何同时成为一个
所以,在Strawberry Perl中,%ENV似乎是一个普通的哈希(至少它没有绑定),
但它似乎也解决了密钥不敏感的问题.鉴于环境,这是有道理的
变量在Power Shell中不区分大小写(我不确定它们之间的确切关系
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 %sn",$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 %sn",$ENV{temp};

# However,%ENV is not a tied hash.
printf "Tie status: %sn",tied(%ENV) // "not a tied variable";

解决方法

以下是来自ActivePerl,但包括Strawberry Perl在内的每个Perl都会给你同样的东西:

>perl -E"use Devel::Peek; Dump(%ENV,1);"
SV = IV(0x74b154) at 0x74b154
  REFCNT = 1
  FLAGS = (TEMP,ROK)
  RV = 0x63e33c
  SV = PVHV(0x62a8ac) at 0x63e33c
    REFCNT = 2
    FLAGS = (SMG,RMG,SHAREKEYS)
    MAGIC = 0x639084                               <-------
      MG_VIRTUAL = &PL_vtbl_env
      MG_TYPE = PERL_MAGIC_env(E)
    ARRAY = 0x640794  (0:30,1:22,2:11,3:1)
    hash quality = 107.7%
    KEYS = 47
    FILL = 34
    MAX = 63

如你所见,%ENV是神奇的.但它并没有束缚;这将是魔术类型“P”而不是“E”.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读