Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Negation Error

by Herkum (Parson)
on Sep 20, 2008 at 22:26 UTC ( [id://712775]=perlquestion: print w/replies, xml ) Need Help??

Herkum has asked for the wisdom of the Perl Monks concerning the following question:

I keep getting this error only on my scripts running on Apache

Use of uninitialized value in negation (-) at /usr/local/perl5.10/lib/ +site_perl/5.10.0/i686-linux/DateTime.pm line 1651.

I have seen mentions of this type of error but no answer on what it is specifically supposed to cause this. Is this an XS error or something else?

Update: I did find the answer to my problem. While you can sort of get away with using cmp to compare dates, it will return an error because it is expecting a package name to be passed. What I should have been using was DateTime->compare( $dt1, $dt2 ) to compare the dates. The silences the error as well as sorts by date.

Replies are listed 'Best First'.
Re: Negation Error
by broomduster (Priest) on Sep 21, 2008 at 00:19 UTC
    I have version 0.4304 of DateTime (the latest). In that version, line 1651 is the return from _compare_overload:
    sub _compare_overload { # note: $_[1]->compare( $_[0] ) is an error when $_[1] is not a # DateTime (such as the INFINITY value) return $_[2] ? - $_[0]->compare( $_[1] ) : $_[0]->compare( $_[1] ) +; }
    _compare_overload is overloaded to <=> and cmp for DateTime objects. So a good place to start tracking this down would be any place you compare DateTime objects (recognizing that the offending call/comparison may be coming from some other module that you are using).

      OK, that is bizarre, considering I don't see it anywhere else in my application, but at least you pointed something to look at.

      The issue is that I take Date/Time from a database and cast all the rows as DateTime objects. So when I see a generic error like this, it makes me nervous as hell because I have no idea where to start because I am not doing anything special on the web server.

      Poking around for DT comparisons, that I can do. I certainly hope it is not in something that I did not write. :)

        Do you sort DateTime objects? The default sorter is $a cmp $b.
Re: Negation Error
by GrandFather (Saint) on Sep 20, 2008 at 22:40 UTC

    "Use of uninitialized value" is generated by Perl when you attempt to use the contents of a variable who's value hasn't been set. The actual error may be in either your code (you supply an uninitialised value for a parameter for example) or it may be an error in the module.


    Perl reduces RSI - it saves typing

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://712775]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2024-04-24 17:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found