Use of uninitialized value in Kernel::System::Time

Hello, in Kernel::System::Time line 236 Perl issues a warning "Use of uninitialized value". It is this code snippet: # match mail time format elsif ($Param{String} =~ /((...),\s+|)(\d\d|\d)\s(...)\s(\d\d\d\d)\s(\d\d|\d):(\d\d|\d):(\d\d|\d)\s((\+|\-)(\d\d)(\d\d)|...)/) { my $DiffTime = 0; if ($10 eq '+') { # $DiffTime = $DiffTime - ($11 * 60 * 60); # $DiffTime = $DiffTime - ($12 * 60); } elsif ($10 eq '-') { # $DiffTime = $DiffTime + ($11 * 60 * 60); # $DiffTime = $DiffTime + ($12 * 60); } The warning is in the line with "if ($10 eq '+') {" because $10 is undef. What is the regexp supposed to match? Why is there a pipe symbol after "/((...),\s+" and before the ")"? Could this be the problem? Thanks, bye, Uwe

Hi, You get this error because $10 isn't populate by you regex. After this line /((...),\s+|)(\d\d|\d)\s(...)\s(\d\d\d\d)\s(\d\d|\d):(\d\d|\d):(\d\d|\d)\s((\+|\-)(\d\d)(\d\d)|...)/) add following code to check why $10 is empty $Self->{LogObject}->Log(Priotity => 'notice',Message=>"1 -> $1 2 -> $3 ....to $10"); Cordialement / Regards Alexandre FOUREY Consultant alexandre@fourey.fr Cell Phone 33 (0)6 67 67 50 12 Uwe Voelker wrote:
Hello,
in Kernel::System::Time line 236 Perl issues a warning "Use of uninitialized value". It is this code snippet:
# match mail time format elsif ($Param{String} =~ /((...),\s+|)(\d\d|\d)\s(...)\s(\d\d\d\d)\s(\d\d|\d):(\d\d|\d):(\d\d|\d)\s((\+|\-)(\d\d)(\d\d)|...)/) { my $DiffTime = 0; if ($10 eq '+') { # $DiffTime = $DiffTime - ($11 * 60 * 60); # $DiffTime = $DiffTime - ($12 * 60); } elsif ($10 eq '-') { # $DiffTime = $DiffTime + ($11 * 60 * 60); # $DiffTime = $DiffTime + ($12 * 60); }
The warning is in the line with "if ($10 eq '+') {" because $10 is undef.
What is the regexp supposed to match? Why is there a pipe symbol after "/((...),\s+" and before the ")"? Could this be the problem?
Thanks, bye, Uwe _______________________________________________ OTRS mailing list: dev - Webpage: http://otrs.org/ Archive: http://lists.otrs.org/pipermail/dev To unsubscribe: http://lists.otrs.org/cgi-bin/listinfo/dev

On 12/23/05, Alexandre FOUREY
Hi,
You get this error because $10 isn't populate by you regex.
After this line /((...),\s+|)(\d\d|\d)\s(...)\s(\d\d\d\d)\s(\d\d|\d):(\d\d|\d):(\d\d|\d)\s((\+|\-)(\d\d)(\d\d)|...)/)
add following code to check why $10 is empty $Self->{LogObject}->Log(Priotity => 'notice',Message=>"1 -> $1 2 -> $3 ....to $10");
It'd also be useful to log $Param{String} so you know what is being parsed by the regexp. Bryan

On 12/23/05, Uwe Voelker
Hello,
in Kernel::System::Time line 236 Perl issues a warning "Use of uninitialized value". It is this code snippet:
# match mail time format elsif ($Param{String} =~ /((...),\s+|)(\d\d|\d)\s(...)\s(\d\d\d\d)\s(\d\d|\d):(\d\d|\d):(\d\d|\d)\s((\+|\-)(\d\d)(\d\d)|...)/) { my $DiffTime = 0; if ($10 eq '+') { # $DiffTime = $DiffTime - ($11 * 60 * 60); # $DiffTime = $DiffTime - ($12 * 60); } elsif ($10 eq '-') { # $DiffTime = $DiffTime + ($11 * 60 * 60); # $DiffTime = $DiffTime + ($12 * 60); }
The warning is in the line with "if ($10 eq '+') {" because $10 is undef.
What is the regexp supposed to match? Why is there a pipe symbol after "/((...),\s+" and before the ")"? Could this be the problem?
It matches the beginning of a date in a mail message. ie: Date: Thu, 22 Dec 2005 23:07:24 -0500 (EST) The 'pipe symbol' is a logical OR. That part of the regexp says "anything followed by a space OR nothing". I think the whole if/elsif block should be commented out, since it's not actually doing anything. It looks like the regexp has changed number of parameters since the if/elsif block was last used (I can't see how $10 would ever be + or -, isn't it the first 2 digits of the timezone?). Bryan

# match mail time format elsif ($Param{String} =~ /((...),\s+|)(\d\d|\d)\s(...)\s(\d\d\d\d)\s(\d\d|\d):(\d\d|\d):(\d\d|\d)\s((\+|\-)(\d\d)(\d\d)|...)/
It matches the beginning of a date in a mail message. ie:
Date: Thu, 22 Dec 2005 23:07:24 -0500 (EST)
The 'pipe symbol' is a logical OR. That part of the regexp says "anything followed by a space OR nothing".
This is stupid. Then use "\s*". I'm not sure if the pipe groups inside the bracket, so that the first part is: - match 3 chars (...) followed by comma (and spaces) OR - nothing at all I think the pipe inside a bracket groups the entire part regexpes. So this regexp is WRONG.
I think the whole if/elsif block should be commented out, since it's not actually doing anything. It looks like the regexp has changed number of parameters since the if/elsif block was last used (I can't see how $10 would ever be + or -, isn't it the first 2 digits of the timezone?).
The last bracket has the same problem with the pipe. It matches the timezone OR 3 chars. If it doesn't match the timezone (e. g. there is no timezone) then $10 doesn't get populated. So comes the warning when comparing $10 to '+' or '-'. Someone with commit rights, please care about this. Change it or use a CPAN module for date parsing. There are plenty of them. Thanks, bye, Uwe

On 12/23/05, Uwe Voelker
I think the pipe inside a bracket groups the entire part regexpes. So this regexp is WRONG.
Agreed. Probably why the guts of the if/elsif block is commented out.
Someone with commit rights, please care about this. Change it or use a CPAN module for date parsing. There are plenty of them.
Also agreed, reinventing the wheel is silly. Bryan
participants (3)
-
Alexandre FOUREY
-
Bryan Fullerton
-
Uwe Voelker