in reply to Ternary operators

geistberg:

No, you didn't make it angry.

Let's take a look at the second loop first: Each time through the loop, you set a hash key to 1 if the current iteration of the loop ($_) matches the hash key. So in each iteration, you're setting only one key.

In your first loop, however, you *always* set the value of each element: to 1 if the loop variable matches the hash key, and 0 otherwise, and the last iteration "wins".

In short: the first loop sets each key to this or that. The second loop sets a key if there's a match.

...roboticus

When your only tool is a hammer, all problems look like your thumb.