I do have the following simple code:
my $TimeZone = $hCache->{'TimeZone'}; # Cache gets filled earlier my $DateTime = DateTime->now(); $DateTime->set_time_zone($TimeZone); This code runs in an application server which is basically a long running perl process that accepts incoming network connections.
From time to time this applicationserver gets somehow "dirty", and the code above is printing the following error:
The 'name' parameter ("Europe/Berlin") to DateTime::TimeZone::new was a 'glob', which is not one of the allowed types: scalar at /srv/epages/eproot/Perl/lib/site_perl/linux/DateTime.pm line 1960.
When I try to debug the variable "$TimeZone" I'm getting no further details.
E.g.
print ref($TimeZone); # prints nothing (scalar?) print $TimeZone; # prints "Europe/Berlin" The code works if I'm forcing the timezone to be a string again, like so:
my $TimeZone = $hCache->{'TimeZone'}; # Cache gets filled earlier my $DateTime = DateTime->now(); $DateTime->set_time_zone($TimeZone.""); My questions are:
- If 'glob' is not a reference, how can I debug the variable properly?
- How can I create a 'glob' variable? What is the syntax to it? I'm quite sure that my huge codebase has some accidents in it, but I don't know what to search for.
- Is there a way to 'monitor' the variable? Basically, getting a stacktrace if the variable changes
EDIT: 2023-04-13
With the use of ChatGPT I was able to resolve the problem. It turns out that perl's "constant folding" was causing the issue. Replacing the affected constants with sub MYCONSTANT { "MyValue" } resolved the issue by preventing "constant folding" for the relevant constants. The challenge was to actually find the correct constant this applies to.
ref(\$var)will returnGLOBfor a glob. For example,perl -e'$x = *STDOUT; CORE::say ref(\$x)'*is the sigil for globs.*foomeans "the glob namedfooin the current package", just like$xrefers to the scalar namedx.