in reply to My 'perldar' tells me there is a 'better' solution for this list operation

I see that two responses use a construct like
my %h1; @h1{@l2}=();
I must admit I have seen this before (especially the second line) and I don't understand it. Is it just shorthand for populating a hash's keys collection with the elements of an array? Almost like
keys(%h1)=@l2; ?
Thanks,
T
P.S. I had no other word for that kind of intuitive feel for coding.

_________________________________________________________________________________

I like computer programming because it's like Legos for the mind.

Replies are listed 'Best First'.
Re^2: My 'perldar' tells me there is a 'better' solution for this list operation
by revdiablo (Prior) on Nov 04, 2006 at 01:45 UTC

    A couple of quick examples may make it easier to understand what a hash slice is doing. This code:

    @hash{"one", "two", "three"} = 1 .. 3;

    Is equivalent to:

    ($hash{one}, $hash{two}, $hash{three}) = 1 .. 3;

    And likewise, these are equivalent:

    my @list = @hash{"one", "two", "three"};

    and

    my @list = ($hash{one}, $hash{two}, $hash{three});
Re^2: My 'perldar' tells me there is a 'better' solution for this list operation
by Roy Johnson (Monsignor) on Nov 03, 2006 at 22:53 UTC
    It's a hash slice, for populating multiple values of a hash from a list.

    Caution: Contents may have been coded under pressure.