Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Why does ‘keys’ need a named hash?

by Anonymous Monk
on Apr 05, 2017 at 21:26 UTC ( #1187190=note: print w/replies, xml ) Need Help??


in reply to Why does ‘keys’ need a named hash?

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.

  • One is anonymous hash constructor: { @list }
  • The other is hash dereference syntax: %{ $href }
  • You can combine the two to produce a hash from a list, and then, make it list again: %{ { @list } }.
    In the process, duplicate keys are squashed.

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1187190]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2022-01-23 12:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (63 votes). Check out past polls.

    Notices?