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
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |