From inside out:
- First the two hashes are flattened to lists, which are combined to a long list.
- Building a new (anonymous) hashref will eliminate duplicated entries from that hash ¹
- To be able to extract² the keys you still need to dereference this ano-hashref with %{..}.
step by step:
DB<111> %hash1= (a=>1,b=>2) => ("a", 1, "b", 2) DB<112> %hash2= (a=>1,c=>3) => ("a", 1, "c", 3) DB<113> (%hash1, %hash2) => ("a", 1, "b", 2, "c", 3, "a", 1) DB<115> + {%hash1, %hash2} => { a => 1, b => 2, c => 3 } DB<117> %{ {%hash1, %hash2} } => ("c", 3, "a", 1, "b", 2) DB<118> keys %{ {%hash1, %hash2} } => ("c", "a", "b")
Cheers Rolf
UPDATES:
¹) because repeated keys will be overwritten.
²) at least with older perl-versions, see Athanasius' remark
In reply to Re: Syntax explanation required
by LanX
in thread Syntax explanation required
by ghosh123
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |