in reply to how to merge Hash

Or even
@hash1{keys %hash2} = values %hash2;
However, if there are any common keys, the last value assigned will be retained.

-QM
--
Quantum Mechanics: The dreams stuff is made of

Replies are listed 'Best First'.
Re^2: how to merge Hash
by Anonymous Monk on Jun 10, 2012 at 12:31 UTC

    can you please explain me the above code when you assigned the values of %hash2 to @hash1 how it is reflecting in %hash1

      There is no array "@hash1" there is only the hash "%hash1".

      This is called a hash slice , and in a quirk of perl syntax uses the @ sigil instead of %

      my %foo; @foo{ 'hash', 'slices' } = ( 'use', 'curly braces' );

      my @bar; @bar[ 1,2,3,4 ] = ( 'array', 'slices', 'use', 'square brackets' );

      Say it with me:

      { 'hashes', 'are', 'curly', 'ones' }

      [ 'arrays', 'are', 'square' ]

      ( 'lists are round' )