in reply to How a for() assignment works

Wow, you caused me to have quite the headslap moment. At first I was thinking, why does the lc get assigned to a new variable? So I played around with it and realized for the first time that $var in this construct is an alias and not a copy. *headslap*

Could you not, at least in this example, use a map? Like, map { print ("Value: " . $hash{lc($_)}); } @valuesIs it uncouth to use map this way?

Edit: Destroyed by better and faster answers!

Replies are listed 'Best First'.
Re^2: How a for() assignment works
by NetWallah (Canon) on Mar 06, 2008 at 21:36 UTC
    Yes - I consider it uncouth.

    "map" (and "grep") return lists. If you are not using the returned values, and merely looping, you should use "for".

         "As you get older three things happen. The first is your memory goes, and I can't remember the other two... " - Sir Norman Wisdom

      Your use of "uncouth" seems a bit harsh, especially given that FYI, starting with Perl 5.8.1 "map" no longer returns anything when called in void context. See Perl 5.8.1 Miscellaneous-Enhancements for more.

      Update: Sorry about that NetWallah. I missed it in the OP due to the poor formatting. Thanks for pointing it out! I will strike out that portion of my message (and bold the updates).

        "uncouth" was the language used in the O.P's post.

        Thanks for the update on the "map" update. Even with that in mind, I'm sure most programmers would agree that "for" is preferable when the return value is unused, since that usage is better understood, and you do not need to look around to verify that the context is indeed void.

        "map", for me, immediately brings into question what is being done with the returned value.

             "As you get older three things happen. The first is your memory goes, and I can't remember the other two... " - Sir Norman Wisdom