Wow! It is not often that BrowserUK makes a typo (his code sets just the first key). I think he meant: my %hash;
@hash{qw[ a b c f t u] } = ('toto') x 6;
@hash{qw[ b g k p ]} = ('titi') x 4;
My personal favorite is:my %hash;
my @array = qw[ a b c f t u];
@hash{@array } = ('toto') x @array;
Update:Following a request from blazar: the typos made by BroswerUK were that the parentheses were omitted from the lhs of the x operator in both cases, and the final line was terminated with a comma instead of a semi-colon. It was probably the keyboard at fault - I have one just like it.
Anyway, I prefer my solution ("My personal favorite") because there is nothing to change when the array changes size. |