Perl:变量值为';全球';,但应该是';标量';
我有以下简单的代码:Perl:变量值为';全球';,但应该是';标量';,perl,variables,glob,Perl,Variables,Glob,我有以下简单的代码: my $TimeZone = $hCache->{'TimeZone'}; # Cache gets filled earlier my $DateTime = DateTime->now(); $DateTime->set_time_zone($TimeZone); 此代码在应用程序服务器中运行,该服务器基本上是一个长时间运行的perl进程,它接受传入的网络连接 此应用程序服务器有时会变得“脏”,上面的代码会打印以下错误: DateTime::Time
my $TimeZone = $hCache->{'TimeZone'}; # Cache gets filled earlier
my $DateTime = DateTime->now();
$DateTime->set_time_zone($TimeZone);
此代码在应用程序服务器中运行,该服务器基本上是一个长时间运行的perl进程,它接受传入的网络连接
此应用程序服务器有时会变得“脏”,上面的代码会打印以下错误:
DateTime::TimeZone::new的“name”参数(“Europe/Berlin”)为
不是允许的类型之一的“glob”:位于
/srv/epages/eproot/Perl/lib/site_Perl/linux/DateTime.pm行1960
当我试着调试变量“$TimeZone”时,我没有得到进一步的细节
例如
如果我再次将时区强制为字符串,则代码可以工作,如下所示:
my $TimeZone = $hCache->{'TimeZone'}; # Cache gets filled earlier
my $DateTime = DateTime->now();
$DateTime->set_time_zone($TimeZone."");
我的问题是:
@a = 4..6; # Creates glob *main::a containing a reference to the new array.
由于glob本身就是包变量,您只需提及它,就可以使glob存在
my $x = *glob; # The glob *main::glob is created by this line at compile-time.
请注意,文件句柄通常通过globs访问。例如,open(my$fh,'sub{$\u1]},
set=>sub{cluck(“变量$[1]modified”);},
);
我的$x;
演员($x,$wiz,q{$x});
$x=123;#第14行
'
在-e第9行修改变量$x。
main::uu ANON(标量(0x50bcee23c0),“\$x”)在-e第14行调用
eval{…}在-e第14行调用
需要做更多的工作来检测散列或数组是否发生更改,但上述内容可用于监视散列和数组的元素。
ref(\$var)
将返回GLOB
,以获取GLOB。例如,perl-e'$x=*STDOUT;核心::说ref(\$x)
谢谢。你知道星号(*)是否总是创建GLOBs的方式吗?*
是GLOBs的标志*foo
表示“当前包中名为foo
的glob”,就像$x
表示名为x
的标量一样。这非常有用!谢谢。也许你能帮我进一步解释一下?我有个目标。。。但不知从哪里来,Perl正在将属性转换为typeglobs(参见屏幕截图)。您知道Perl对象处理的更多细节吗?截图:@xsigndll:问一个新问题问一个新问题。Perl通常不会这样做:包含所有细节(是否包含任何OO框架?),最好的方法是发布一个。
my $x = *glob; # The glob *main::glob is created by this line at compile-time.
$fh # Reference to glob that contains a reference to an IO.
*$fh # Glob that contains a reference to an IO.
*$fh{IO} # Reference to an IO.