in reply to Where does time come from? CORE::GLOBAL:time no honored.

Why does "x time()" have such a different value than "x $time"?

Because 25 seconds went by between the assignment to $time and the second call to time()?

I have no problem overridding time().

$ cat time.pl use strict; use warnings; BEGIN { no warnings qw(redefine); *CORE::GLOBAL::time = sub { 4 }; } my $time = time(); 1; $ perl -d time.pl Loading DB routines from perl5db.pl version 1.28 Editor support available. Enter h or `h h' for help, or `man perldebug' for more help. main::(time.pl:10): my $time = time(); DB<1> n main::(time.pl:12): 1; DB<1> x $time 0 4 DB<2> x time() 0 4 DB<3> q

Replies are listed 'Best First'.
Re^2: Where does time come from? CORE::GLOBAL:time no honored.
by Anonymous Monk on Mar 26, 2009 at 22:35 UTC
    Unfortunately that's not the case. I stepped through the code and evaluated them both within a few seconds of each other. Also my mock time function returns a fixed time so I would expect them to be the same. In fact "x time()" in the debugger returns the same time every time.

      That was your cue to tell us one of them was the time returned by your function, one of them is now, and to tell us which one is which. If that's the case, please do so now. If it isn't the case, please explain what your numbers are.

      Do you get the same output from my program as I do? If so, you haven't provided enough info, since overriding time clearly works for you. Please provide more information, preferably less than 25 lines that we can run to repeat the problem.

      If you do not get the same output from my program as I do, please provide the output you do get, the output of perl -V.

        The program I am running is large and I have not been able to reproduce the problem in a small example. You're right, I forgot to mention that the value returned by time() in the program code is not the value returned by my function, but calling time() in the debugger does return the value from my function. Witness:
        500: my $time = time(); DB<4> n Queue::MySQLQ::dequeue(/Users/foo/lib/Queue/MySQLQ.pm:501): 501: my $expire_time = $time + $WORKER_HEARTBEAT_FAILURE; DB<4> x $time 0 1238124047 DB<5> x time() 0 1238124062 DB<6> sleep 2 DB<7> x time() 0 1238124062
        What situation could cause time() in the program code to run different code than time() called in the debugger?

        Thanks for all the help.