Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re: Sorting Puzzle

by imp (Priest)
on Feb 20, 2007 at 21:08 UTC ( #601208=note: print w/replies, xml ) Need Help??

in reply to Sorting Puzzle

The numbers are too large for numeric comparison without using bigint

Replies are listed 'Best First'.
Re^2: Sorting Puzzle
by willfould (Novice) on Feb 20, 2007 at 21:19 UTC
    Thank you! I am creating a numeric sorting key on start/end dates and times. I was originally wanting to convert the times to unix timestamp but could not find a fast way to do that. With the unix timestamp, this would be trivial but require the extra conversion step. Is there a datetime to unix timestamp function?
      Datetime. It also provides sorting. It also provides intervals which sounds like what you're interested in.

      Less applicable to the question but more important, imho, is that it handles all the nasty edgecases that any developer who didn't write Datetime shouldn't be bothered to know about handling dates and times. This would include the situations when a minute can have 59 seconds, 61 seconds, and even 62 seconds. (Yes, those situations do exist in really odd circumstances, but it would suck if you accidentally ran into one of them, right?)

      My criteria for good software:
      1. Does it work?
      2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
      Time::Piece makes it fairly easy, but you would have to benchmark it against other solutions to see what works for you. How much data are you dealing with?
      use Time::Piece; use strict; use warnings; my $date = '20070301103000'; my $start = Time::Piece->strptime($date, "%Y%m%d%H%M%S")->epoch; print $start, "\n";

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://601208]
and God said, "Let Newton be!"...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (10)
As of 2018-07-16 15:00 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (342 votes). Check out past polls.