Problems? Is your data what you think it is? | |
PerlMonks |
Re: Why does ‘keys’ need a named hash?by Anonymous Monk |
on Apr 05, 2017 at 21:26 UTC ( [id://1187190]=note: print w/replies, xml ) | Need Help?? |
I read the answers above and feel the issue could be further clarified... The question is about braces and the ways in which they are used in perl. To work with hashes, two useful syntaxes should be understood.
With map, the braces have an ambiguous meaning: they could be a hash constructor, or (more commonly), a BLOCK. To avoid confusion, you might want to rewrite the map expression using parentheses this time: map(( $_ => 1 ), @list). Finally, if you intend to use a hash (a data structure that cannot have duplicate keys) to implement the uniq routine, you must at some step construct one! Either anonymous or named one; but for anon case, you'll have the extra braces.
In Section
Seekers of Perl Wisdom
|
|