in reply to time as number

If you really do just need the time as an integer, why are we going the complicated way around?

localtime is an integer, just not a very human-readable one. Just use that -- print localtime -- sort by it, do compares with it, and re-interpret it into human-readable format when it needs to be read by humans...
--

“Every bit of code is either naturally related to the problem at hand, or else it's an accidental side effect of the fact that you happened to solve the problem using a digital computer.”
M-J D

Replies are listed 'Best First'.
Re: Re: time as number
by demerphq (Chancellor) on Mar 03, 2003 at 17:14 UTC

    Just use that -- print localtime -- sort by it, do compares

    Er, I dont think thats right:

    D:\perl\PerlToc>perl -e "print ''.localtime" Mon Mar 3 18:12:15 2003
    Which doesn't provide a sortable format. Unless you want your dates sorted by day of week :-)

    ---
    demerphq


      But surely you've forced scalar context on it there by making it a string. What happens if you just do "print localtime"? And anyway, who needs localtime anyway. You can just do it with time and local it, again, later when you need your human-readable format.
      --
      “Every bit of code is either naturally related to the problem at hand, or else it's an accidental side effect of the fact that you happened to solve the problem using a digital computer.”
      M-J D

        But surely you've forced scalar context on it there by making it a string. What happens if you just do "print localtime"?

        You would end up sorting by second first etc... And reversing it doesn't help. Don't forget that localtime() returns

        ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time +);
        in list context.

        You can just do it with time and local it, again, later when you need your human-readable format.

        Yup. That works much better. ;-) Although personally I find that YYYYMMDDHHMMSS can be a quite useful representation of time.

        ---
        demerphq