perlquestion
NetWallah
Gentle Monks, <p>
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).<p>
I'd like to do it all within the hash init (no separate statements). I have the following working solution:
<c>
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
</c>
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.<p>
Thank you.<p>
<b>Update:</b> I'm also curious how this would look in perl6. (zip, perhaps ?)
<!-- Node text goes above. Div tags should contain sig only -->
<div class="pmsig"><div class="pmsig-159887">
<p><small>
"You're only given one little spark of madness. You mustn't lose it." - Robin Williams
</small></p>
</div></div>