They both do essentially the same thing--build a hash from the lines in a file. However, there are a couple of differences, and an anomaly.
The maps do the same thing--build the key/value pairs that get assigned to the hash, using each line from the file as the key (with the trailing newline removed by chomp), and setting the value to a constant. The first sets all the values to 1, the latter sets them to undef. For lookup purposes, where you are not going to use the value for anything, the latter is a better choice as it saves a little space. No reason to store a bunch of '1's that you will never use.
The first example builds an anonymous hash and assigns a reference to it, to the scalar $hist. Nothing wrong in that, except that it forces you to indirect through the reference to get at it's elements. Ie. $hist->{key} = 'value'; which is slightly clumsier that a simple hash, as used in the second example: $hash{key} = 'value';. Not much in it, but I find the former easier unless there is a good reason for using a reference.
Finally, the anomaly. In the first example, the lines are read into an anonymous array first: [<FILE>]. This anonymous array is then dereferenced to produce a list: map{...} @{ [<FILE>] }. These two steps are unnecessary as, using readline (the <FILE> operator) directly as in the second example achieves exactly the same thing, supplying a list to map, without going through the intermediate steps of creating and dereferencing an anonymous array and thereby temporarily consuming extra space.
All in all, the second version is preferable to the first.
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] [d/l] [select] |