++ 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.


In reply to Re: Coolest way to decode YYYYMMDD? by hdb
in thread Coolest way to decode YYYYMMDD? by locked_user sundialsvc4

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.