Note: This was an accidental reply to "Array of variables" which was originally posted in April 2017. It was suggested by ++jdporter that I consider it for re-parenting.

[See "Re^5: Array of variables" for an explanation of the striking of the "Note:".]

G'day Michael W,

To my mind, the following is cleaner, more readable, and more maintainable. Here's the basic changes:

#!/usr/bin/env perl use strict; use warnings; my %months; @months{qw{Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec}} = '01' .. '12'; my $out_fmt = '%4d-%s-%02d'; my ($Map_Request_Date, $Map_Due_Date, $Map_Cutover_Date, $Map_Complete_Date, $Map_Approved_Date ) = ( 'Jan 1 2017 12:00', 'Jan 31 2017 12:00', 'Feb 28 2017 23:59', 'Mar 1 2017 12:01', 'Dec 31 1999 0:01' ); my @var_refs = \( $Map_Request_Date, $Map_Due_Date, $Map_Cutover_Date, $Map_Complete_Date, $Map_Approved_Date ); print "$$_\n" for @var_refs; for (@var_refs) { my ($m, $d, $y, undef) = split ' ', $$_; $$_ = sprintf $out_fmt, $y, $months{$m}, $d; } print "$$_\n" for @var_refs;

Output:

Jan 1 2017 12:00 Jan 31 2017 12:00 Feb 28 2017 23:59 Mar 1 2017 12:01 Dec 31 1999 0:01 2017-01-01 2017-01-31 2017-02-28 2017-03-01 1999-12-31

Update: It looks like I mis-clicked on your last post instead of your current post, and replied to that. Hopefully, there's still some useful information. [See "Re^5: Array of variables" for some more details about that.]

— Ken


In reply to Re: Array of variables by kcott
in thread Array of variables by Michael W

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.