Perl: using an uninitialized value in numeric lt (<) in / Date / Manip.pm

It puzzled me. This code worked on a different server, but failed on Perl v5.8.8 with Date :: Manip loaded from CPAN today.

 Warning: Use of uninitialized value in numeric lt (<) at /home/downside/lib/Date/Manip.pm line 3327. at dailyupdate.pl line 13 main::__ANON__('Use of uninitialized value in numeric lt (<) at /home/downsid...') called at /home/downside/lib/Date/Manip.pm line 3327 Date::Manip::Date_SecsSince1970GMT(09, 16, 2008, 00, 21, 22) called at /home/downside/lib/Date/Manip.pm line 1905 Date::Manip::UnixDate('today', '%Y-%m-%d') called at TICKER/SYMBOLS/updatesymbols.pm line 122 TICKER::SYMBOLS::updatesymbols::getdate() called at TICKER/SYMBOLS/updatesymbols.pm line 439 TICKER::SYMBOLS::updatesymbols::updatesymbol('DBI::db=HASH(0x87fcc34)', 'TICKER::SYMBOLS::symbol=HASH(0x8a43540)') called at TICKER/SYMBOLS/updatesymbols.pm line 565 TICKER::SYMBOLS::updatesymbols::updatesymbols('DBI::db=HASH(0x87fcc34)', 1, 0, -1) called at dailyupdate.pl line 149 EDGAR::updatesymbols('DBI::db=HASH(0x87fcc34)', 1, 0, -1) called at dailyupdate.pl line 180 EDGAR::dailyupdate() called at dailyupdate.pl line 193 

Simple code:

 sub getdate() { my $err; ## today &Date::Manip::Date_Init('TZ=EST5EDT'); my $today = Date::Manip::UnixDate('today','%Y-%m-%d'); ## today date ####print "Today is ",$today,"\n"; ## ***TEMP*** return($today); } 

That is right; Date :: Manip does not work for "today" .

A string in Date :: Manip that does not work:

  my($tz)=$Cnf{"ConvTZ"}; $tz=$Cnf{"TZ"} if (! $tz); $tz=$Zone{"n2o"}{lc($tz)} if ($tz !~ /^[+-]\d{4}$/); my($tzs)=1; $tzs=-1 if ($tz<0); ### ERROR OCCURS HERE 

So Date :: Manip assumes that $Cnf was initialized with "ConvTZ" or "TZ" elements. They are initialized in Date_Init , so you should take care of them.

This is just a failure in my big program. If I just extract the β€œ getdate() ” above and run it autonomously, there is no error. So something about the global environment that affects this.

This seems to be a well-known but incomprehensible problem. If you search Google for β€œUsing Uninitialized Date-Date Manipulation,” there are about 2,400 hits. This error has been reported with MythTV and grepmail .

+4
source share
4 answers

This is a bug in Date :: Manip version 5.48-5.54 for Win32. I had difficulty using standard / day time zone options, for example. "EST5EDT", "US / Eastern". The only time clocks that seem to work are those that don't have daylight, for example. 'Est'.

In the Date :: Manip module, you can disable the time zone conversion processing:

 Date::Manip::Date_Init("ConvTZ=IGNORE"); 

This will have unwanted side effects if you relate to dates correctly . I would not use this workaround if you are not sure that you will never process dates from different time zones.

+3
source

It is almost certain that your host has no definition for the time zone that you specify, which causes the value undefined.

Have you checked if the TZ definition file with the same name really exists on the host?

+2
source

Date :: Manip must be autonomous. It has a list of all its time zones in its own source, following "$ zonerfc =".

0
source

Can you try one step through the debugger to see what exactly is going wrong? It may just be% Zone, which is wrong -% tz can be configured correctly on line 1 or 2, but then the search on line 3 failed, resulting in undef.

Edit:% Date :: Manip :: Cnf and% Date :: Manip :: Zone are global variables, so you can take a dump from them before and after calling Date :: Manip :: Date_Init. If I read the source correctly, then % Cnf must contain the basic skeleton of configuration parameters before calling Date_Init and% Zone must be empty; after Date_Init, TZ should have your chosen value, and% Zone should be populated with a timezone lookup table.

I see a link to .DateManip.cnf in% Cnf, there might be something to look at - is it possible that you have such a file in your home directory or in the current working directory that overrides the default settings

-2
source

Source: https://habr.com/ru/post/1276768/


All Articles