NetWallah has asked for the wisdom of the Perl Monks concerning the following question:
Gentle Monks,
I'm trying to get an "elegant" solution to initializing a hash such that it includes a parsed date (i.e. pieces of the date are easily accessible).
I'd like to do it all within the hash init (no separate statements). I have the following working solution:
I'm hoping wiser monks could help me get rid of the hack (ab)use of "map", and %_ and make this more "elegant" and/or canonical.perl -E 'my %stuff=(otherinfo=>"this and that", dateinfo=>{local %_, map({()} @_{qw|sec min hour mday mon year wday yday isdst|} =localtime(time)), %_}); say "sec=",$stuff{dateinfo}{sec}, " year=",$stuff{dateinfo}{year}' #-- Output -- #sec=2 year=114
Thank you.
Update: I'm also curious how this would look in perl6. (zip, perhaps ?)
"You're only given one little spark of madness. You mustn't lose it." - Robin Williams
Back to
Seekers of Perl Wisdom