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

I am using time() in Linux system to get current epoch. most of the cases, it gives correct epoch. but 3/4 times in every hour, it gives the epoch which is ahead of the current time.

have a look at my function,

sub fetch_time { Other variables declarations ... my($cur_ts); <-- variable in which I am going to receive the epoch Other variables declarations ... # get the current timestamp $cur_ts = time(); <-- fetching current epoch print "$cur_ts;\n"; Other operations ... } Samples sample 1: system epoch - 1234867548 epoch printed - 1234871946 sample 2: system epoch - 1234868856 epoch printed - 1234873254 sample 3: system epoch - 1234928039 epoch printed - 1234932437

Note: All the time, the difference coming in the range 4000 and above.

What may be the cause for this problem?

Replies are listed 'Best First'.
Re: epoch time from time()
by targetsmart (Curate) on Feb 18, 2009 at 08:43 UTC
    on what basis you are comparing epoch times, you have two times, one is the system time, the other is from where?. please give more clarity of what are you trying to achieve and compare.
    use Markup in the Monastery before posting code

    Vivek
    -- In accordance with the prarabdha of each, the One whose function it is to ordain makes each to act. What will not happen will never happen, whatever effort one may put forth. And what will happen will not fail to happen, however much one may seek to prevent it. This is certain. The part of wisdom therefore is to stay quiet.
Re: epoch time from time()
by ikegami (Patriarch) on Feb 18, 2009 at 14:15 UTC

    Could the difference be 3600? That's one hour. I'm guessing you have two systems and the time zone info is wrong on one of them.

    Your node is unreadable. Please use <p> at the start of every paragraph and <c>...</c> around code and preformatted data.

Re: epoch time from time()
by dHarry (Abbot) on Feb 18, 2009 at 08:52 UTC

    Very strange indeed. I have no explanation for the big differences in time. I see nothing wrong in the code you post but then again you don't post too much... Could you post the complete code? The only thing I can think of right now is that you accidentally modify $cur_ts somewhere?!