xsi*_*dll 2 variables perl glob
我确实有以下简单的代码:
my $TimeZone = $hCache->{'TimeZone'}; # Cache gets filled earlier
my $DateTime = DateTime->now();
$DateTime->set_time_zone($TimeZone);
Run Code Online (Sandbox Code Playgroud)
这段代码运行在一个应用服务器中,它基本上是一个长时间运行的 perl 进程,它接受传入的网络连接。
这个应用程序服务器有时会变得“脏”,上面的代码打印出以下错误:
DateTime::TimeZone::new 的“name”参数(“Europe/Berlin”)是一个“glob”,它不是允许的类型之一:/srv/epages/eproot/Perl/lib/site_perl/ 处的标量linux/DateTime.pm 第 1960 行。
当我尝试调试变量“$TimeZone”时,我没有得到更多细节。
例如
print ref($TimeZone); # prints nothing (scalar?)
print $TimeZone; # prints "Europe/Berlin"
Run Code Online (Sandbox Code Playgroud)
如果我强制时区再次成为字符串,则代码有效,如下所示:
my $TimeZone = $hCache->{'TimeZone'}; # Cache gets filled earlier
my $DateTime = DateTime->now();
$DateTime->set_time_zone($TimeZone."");
Run Code Online (Sandbox Code Playgroud)
我的问题是:
如何创建“glob”变量?
Glob 是“typeglob”的缩写,是一种结构(在 C 语言意义上),其中包含可以在符号表(标量、数组、散列、代码、glob 等)中找到的每种变量类型的字段。它们形成符号表。
Glob 是通过简单地提及一个包变量来创建的。
@a = 4..6; # Creates glob *main::a containing a reference to the new array.
Run Code Online (Sandbox Code Playgroud)
由于 glob 本身就是包变量,因此您只需提及它就可以使 glob 存在。
my $x = *glob; # The glob *main::glob is created by this line at compile-time.
Run Code Online (Sandbox Code Playgroud)
请注意,文件句柄通常通过 glob 访问。例如,使用对包含对 IO 的引用的 glob 的引用进行open(my $fh, '<', ...)填充$fh。
$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.
Run Code Online (Sandbox Code Playgroud)
如果 'glob' 不是引用,我该如何正确调试变量?
ref(\$var)将返回GLOB一个 glob。
@a = 4..6; # Creates glob *main::a containing a reference to the new array.
Run Code Online (Sandbox Code Playgroud)
有没有办法“监控”变量?
是的。你可以给它添加魔法。
my $x = *glob; # The glob *main::glob is created by this line at compile-time.
Run Code Online (Sandbox Code Playgroud)
需要做更多的工作来检测散列或数组是否发生变化,但以上内容可用于监视散列和数组的元素。