Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Sorting Puzzle

by imp (Priest)
on Feb 20, 2007 at 21:08 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2024-04-23 09:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found