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


in reply to Re: map {} list or do {} for list?
in thread map {} list or do {} for list?

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!

Replies are listed 'Best First'.
Re^3: map {} list or do {} for list?
by SuicideJunkie (Vicar) on Apr 11, 2014 at 16:06 UTC

    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?
      لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

        It's a FAQ of its own. Per perl581delta: "map in void context is no longer expensive. map is now context aware, and will not construct a list if called in void context".

        Sorry, I didn't mean to imply that it wasn't optimized away.

        I meant that when reading the code, map says "Hey! Pay attention to the return values of this code block, we're making a list of them."

        It looks like it is well optimised. See my benchmarks, currently at the end of the thread.

        Cheers,
        R.

        Pereant, qui ante nos nostra dixerunt!