Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Coolest way to decode YYYYMMDD?

by hdb (Monsignor)
on Jun 03, 2013 at 08:30 UTC ( #1036693=note: print w/replies, xml ) Need Help??


in reply to Coolest way to decode YYYYMMDD?

++ to all the good technical solutions provided so far. I am surprised that no one has really spotted the underlying philosophical problems implicit in the question. First of all, why using a DateTime object, when only a date has been specified? It seems obvious that at least a time has to be added to the date information before the question can be answered. Completeness of question is one of the highest principles (see for example the works of Douglas Adams). Which time shall we add? Noon, midnight, else? Can we be sure which one is "the best time of the day"™? Time creates other problems, of course, as Time is subject to relativity. Now Einstein has a lot of things to say about this matter, but he had no great tools such as Perl, CPAN and other unnamed utilities at hand. Having clarified the greater issues of the question, let's look at the details: the string '19830501' and the requested answer “May 1,1983?” suggests a pattern of yyyymmdd to be translated into month name, day of month, comma, four digit year, question mark. Splitting up the input first. A recursive solution seems to be the best approach as we first need to split the string into two halves of equal length, and the apply the same to the second half that we have obtained. Recursion is a sound principle applied to all important problems such as Towers of Hanoi™ and others.
While the OP explicitly mentions DateTime to be employed solving his riddle, it seems rather uncool to use the most obvious module available. There are so many modules available on CPAN, so just using only one and the most obvious cannot be a good strategy. Finding the name of the 5th month, for example, is far better done asking "Google"™ Employing useful tools like LWP::UserAgent and HTML::Parser will easily translate "name of 5th month in gregorian calendar" into "May".
One thing is still puzzling, now that we have solved most of the question: why is the input surrounded by single quotes while the required answer has double quotes? Perl is reacting rather different to the types of quotes. The interpolation feature of double quotes allows for writing complicated strings in a short concise way whereas single quotes help the programmer to ignore issues with characters like $, %, and @. By the way, these characters are also called sigils in Perl, stemming from Latin sigillum. The significance of these characters in Perl cannot be underestimated. In any case, the unresolved question of the quotes prevents to provide any usable code here, but I assume that the above exposition will be helpful for you to find the coolest solution yourself.

Replies are listed 'Best First'.
Re^2: Coolest way to decode YYYYMMDD?
by sundialsvc4 (Abbot) on Jun 03, 2013 at 13:42 UTC

    “Unabashed Obfuscation™,” to that level of pure-artistry, definitely calls for an up-vote.   :-)   Touché.   When you get elected, remember us.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1036693]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2018-02-25 00:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When it is dark outside I am happiest to see ...














    Results (312 votes). Check out past polls.

    Notices?