Ever wanted to do:
my @hash{@keys} = @values;
but of course were stopped by the fact that that's a syntax error? So you resort to either
my %hash; @hash{@keys} = @values;
or
my %hash = map { $keys[$_] => $values[$_] } 0..$#keys;
and that just didn't seem clean? Well, here's another idiom that borders on cool or wacky weird, depending on where you're from!
@$_{@keys} = @values for \my %hash;

Replies are listed 'Best First'.
Re (tilly) 1: Declaring and initializing a hash with a list of keys and a list of values
by tilly (Archbishop) on May 15, 2001 at 21:53 UTC
    That depends on fairly subtle scoping semantics. Are you positive that no future Perl will ever localize that hash to the loop? I would be concerned...

      And these 'subtle scoping issues' render the output of Deparse incorrect:

      $ perl -MO=Deparse -e '@$_{1,2,3}=(4,5,6) for \my %hash;print keys %ha +sh' foreach $_ (\my(%hash)) { @$_{1, 2, 3} = (4, 5, 6); } print keys %hash; -e syntax OK

      Thus, people who try to understand it via the Deparsed version may be somewhat disappointed.

      So what? He doesn't access it in the loop. Does it matter if it's localized?
        The purpose of the loop is to initialize a hash that he wants to be available afterwards. If the scoping changes then he has initialized a private hash that disappears before he ever gets a chance to use it. Oops...

        strict would catch this change.

(dws)Re: Declaring and initializing a hash with a list of keys and a list of values
by dws (Chancellor) on May 15, 2001 at 22:16 UTC
    This gets points for being twisted, but it still goes on my "Kids, don't try this before a code review" list. The benefit you get from being able to the the declaration and initialization in one statement is outweighed by the wetware pessimization of making the reader dig to see the my.
Re: Declaring and initializing a hash with a list of keys and a list of values
by MeowChow (Vicar) on May 15, 2001 at 21:43 UTC
    That's rather pathological. I like it :)
       MeowChow                                   
                   s aamecha.s a..a\u$&owag.print