http://qs321.pair.com?node_id=1081976


in reply to map {} list or do {} for list?

map returns a list. It should be used when you want the list being generated as output.

do{...} for should be used when you just want to do things in a loop.

Since you have your statement in void context, you obviously don't want any output. Thus, the for loop is what you want.

Replies are listed 'Best First'.
Re^2: map {} list or do {} for list?
by Random_Walk (Prior) on Apr 11, 2014 at 15:27 UTC

    That was my feeling about map too. But I have seen it used void in a few bits of code recently, and wondered if there was any solid argument for or against, other than it looks wrong :)

    Cheers,
    R.

    Pereant, qui ante nos nostra dixerunt!

      Well, it certainly still works, but its misleading. You're building a big list of results and then immediately throwing it away.

        Wasn't that optimized not to happen in void context?
        لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ