oko1 has asked for the wisdom of the Perl Monks concerning the following question:
My brain does not seem to be working well today; seems like I should be able to do this, but I can't come up with an answer - or even tell if it's possible. I'd appreciate it if the brilliant Monks here could stand in for some of my cerebral capacity... :)
Situation: take a typical hash slice; make an href out of it.
my @data = qw/Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec/; my %h; @h{1..12} = @data; my $x = \%h;
So far, so good. My question is, given the two lists above, how would you create $x without those other temporary variables? I've been fiddling with things like
# This gets me a hash... my %x = map { $_ + 1 => (qw/Jan Feb .../)[$_] } 0 .. 11; # ...but this does not get me a hashref :-\ my $x = \%{ map { $_ + 1 => (qw/Jan Feb .../)[$_] } 0 .. 11 };
and their ilk for a while, and am not getting it. Help would be appreciated!
[ Oh - and - no, this isn't some critical necessity; it's just me, always trying to learn more about Perl idiom. ]
--
"Language shapes the way we think, and determines what we can think about."
-- B. L. Whorf