http://www.perlmonks.org?node_id=452810


in reply to Hash not getting updated

I assume this is just contrived code to ask a question, but, just in case, a hash slice makes the 'foreach' block unnecessary.

my @array = ( 'white', 'blue', 'yellow' ); my %hash; @hash{ @array } = @array;

Or, without the array:

my %hash; @hash{ 'white', 'blue', 'yellow' } = ( 'white', 'blue', 'yellow' );