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

Re^3: sorting dates in YYYYMMDD format

by hdb (Prior)
on Jul 04, 2013 at 07:22 UTC ( #1042352=note: print w/replies, xml ) Need Help??


in reply to Re^2: sorting dates in YYYYMMDD format
in thread sorting dates in YYYYMMDD format

Do you realize, that

join('', (/(..)(..)(....)/)[0,1,2])

does not change a string $_ of length 8 in any way? (Apart from burning CPU cycles...). The regex also does not fit very well when splitting YYYYMMDD into pieces.

Replies are listed 'Best First'.
Re^4: sorting dates in YYYYMMDD format
by Dallaylaen (Friar) on Jul 04, 2013 at 12:49 UTC
    Yes, but the real strings that have to be sorted may not be that easy, containing e.g. rubbish at start, or some punctuation, or - worse - be of different, yet regexpable format. (I don't know for sure, just a thought).
      Yes, but the real strings that have to be sorted may not be that easy ...

      Yes, but do you see that part of the point hdb was making was that  /(..)(..)(....)/ does not extract anything meaningful from a string like  '20130401' because the year winds up as '20' and '13', and the month and day fields wind up stuck together as '0401'. As hdb points out, this only works because all this mess is immediately stuck back together to form the original string — which is then sorted lexicographically, as any number of monks have recommended. The fact that learner@perl specifies test data in the  @dates array in YYYYMMDD format and has a subsequent comment
          @dates;  # DD-MM-YYYY
      further suggests that he or she does not firmly grasp what is going on.

      BTW, a date in the format  '2012-04-01' or  '2012/04/01' or with any other delimiter character or characters will lexi-sort perfectly well as it stands as long as the delimiter(s) at each position are constant!

        You are absolutely right. I've seen a need for extra transformation but there wasn't any.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1042352]
help
Chatterbox?
[marto]: from experience of this side of the fence, it's all about proving to people that you are ITIL compliant, then the client ignores logical processes anyway :P
[marto]: when you work on the outside, for a client, you can make them aware of the stupids, but they don' t always listen :/
[Corion]: Yeah, you can lead them to water, but it's illegal to drown them...
[Discipulus]: Here my solution marto: create a win fake machine insied AD. do a micro fake partition foreach remote partition you wont to monit. put a web server that acept from data from remote systems and full fake partition as needed. fake partition are Mb. ;=)
[marto]: Discipulus yeah, the nuclear industry love fake machines sitting around on a controlled domain :P
[marto]: changing a typo on a website is often a great deal of paper work :P

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (12)
As of 2017-01-24 10:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you watch meteor showers?




    Results (203 votes). Check out past polls.