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


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

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

Replies are listed 'Best First'.
Re^5: map {} list or do {} for list?
by Anonymous Monk on Apr 11, 2014 at 16:44 UTC

    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".

Re^5: map {} list or do {} for list?
by SuicideJunkie (Vicar) on Apr 14, 2014 at 14:30 UTC

    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."

      Well, the same could be said of "$i++;'. In other words, if god had not meant us to throw away results, he wouldn't have given us void context ;-)

Re^5: map {} list or do {} for list?
by Random_Walk (Prior) on Apr 12, 2014 at 12:33 UTC

    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!