in reply to Assigning values to undef hash reference keys two or more at a time

Now I understand which concept to use on the right side but I can't get my values assigned to the left side.

perlreftut says "Whatever you want to do with a reference, Use Rule 1 tells you how to do it. You just write the Perl code that you would have written for doing the same thing to a regular array or hash, and then replace the array or hash name with {$reference} ."

My traditional hash gets the values assigned to keys with this:

my @values = ("value1", "value2", "value3"); @employees{qw(key1 key2 key3)} = @values;
So I thought some form of this would work but I can't get it right.
@{$hashref->{qw/key1 key2 key3/}} = @values; %{$hashref}->{qw/key1 key2 key3/} = @values;
I've tried many more combinations, including moving the brackets all over the place. Is this even close? I need a bigger hint I guess.

Replies are listed 'Best First'.
Re^2: Assigning values to undef hash reference keys two or more at a time
by JadeNB (Chaplain) on Oct 23, 2008 at 20:29 UTC
    Rule 1, which you mention, provides the answer—except that maybe you have the wrong idea of what the ‘hash name’ is. Namely:
    @hash{ qw/key1 key2 key3/ }
    is the slice of the hash named 'hash' (not '%hash') corresponding to the indicated keys. If you want to slice a referent, just stick the (suitably bracketed) reference in place of the name:
    @{ $hashref }{ qw/key1 key2 key3/ }
    (as AnomalousMonk pointed out below).