in reply to Map: Thou Has't Confounded Me For The Last Time! (Referring To The Array You Are Assigning To In Map)
I have always been under the impression that map assigns to a list, like foreach does, but this doesn't seem to be true. In truth, judging from my experiences as well as the form of a map call, map returns a list that the array or hash you have created is _then_ set to.That's exactly what's happening. First the map is fully evaluated. It returns a list, and then that list is stored into the array. Similarly, you could use map without storing it (say, in void context, or passing the result to a function like print, or...) and it would evaluate it fully, and then do whatever it's supposed to with it. Put another way, if you were to write
would you be surpised that it doesn't blow up ("But $a can never be one more than itself!")? No, it first evaluates the new value, and then does the assignment.$a = $a + 1;
|
|---|