Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Array of variables

by kcott (Archbishop)
on Dec 14, 2021 at 20:58 UTC ( [id://11139620]=note: print w/replies, xml ) Need Help??


in reply to Array of variables

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:

  • Moved the static data out of the loop: doesn't need to be redefined on every iteration.
  • Reused the test data from choroba's 3rd code example.
  • Made the elements of the array actual references. You used $Date_Ref which is poorly named because they're strings, not references.
  • The loop now just contains two statements: much easier to read and maintain.
#!/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

Replies are listed 'Best First'.
Re^2: Array of variables
by jdporter (Paladin) on Dec 14, 2021 at 23:30 UTC

    For future reference: You can simply consider the node for re-parenting.

      Thanks and done. I changed the title slightly and added a note about where it came from: I hope that's sufficient.

      — Ken

        To be clear: I didn't suggest reparenting this post, mainly because it already has replies which allude explicitly to its necropostness.
        Also, you implied that you meant it to be a reply to a different node:

        It looks like I mis-clicked on your last post instead of your current post, and replied to that.
        But then you considered it to be promoted to root post:
        Please reparent (with all replies in this subthread) as a top-level SoPW post.

        That's not reparenting. See What do Janitors do?

        In any case, if you know you made an error and want it to be fixed, just /msg gods and we'll fix it with minimal rigamarole.
        But I'm really not inclined to move a post in a way that makes its replies contextless and confusing.

        I reckon we are the only monastery ever to have a dungeon staffed with 16,000 zombies.
Re^2: Array of variables
by eyepopslikeamosquito (Archbishop) on Dec 14, 2021 at 22:20 UTC

      Serendipity is alive and kicking. :-)

      — Ken

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11139620]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2026-04-19 11:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.