in reply to Re^3: Map Vs Foreach
in thread Map Vs Foreach

map{} is a wrong idea if the output isn't being used.
Why? We use functions and operators without using their output all the time (print for instance). What makes map special that's not using its return value is a sin?
I didn't know about that. When did this performance enhancement happen?
6 years ago (5.8.1). After many years of people using the performance penalty of map-in-void-context as an argument not to use map in void context, someone actually produced a one line patch to eliminate that. Didn't stop people from ranting against using map-in-void-context though. Didn't even stop people using the performance argument either.

Besides, wasn't it Larry himself who said that using things in other ways than originally intended isn't bad in itself? That one can enjoy sex, even if you aren't using it to reproduce yourself?

Replies are listed 'Best First'.
Re^5: Map Vs Foreach
by JavaFan (Canon) on Nov 27, 2009 at 12:34 UTC
    To follow up on myself, here's the quote from Larry. He even said it in a debate about map-in-void-context:
    Date: Mon, 1 Nov 1999 15:46:45 -0800 (PST) From: Larry Wall <larry at wall.org> To: hv at crypt0.demon.co.uk Cc: Larry Wall <larry at wall.org>, Simon Cozens <simon at brecon.co.u +k>, perl5-porters at perl.org Subject: Re: grep/map in void context hv at crypt0.demon.co.uk writes: : Isn't the point that (void)'grep EXPR, LIST' is now better written a +s : 'EXPR for LIST'? Or am I misunderstanding your point here? It really doesn't bother me if people want to use grep or map in a voi +d context. It didn't bother me before there was a for modifier, and now that there is one, it still doesn't bother me. I'm just not very easy to bother. The argument against using an operator for other than its primary purpose strikes me the same as the old argument that you shouldn't hav +e sex for other than procreational purposes. Sometimes side effects are more enjoyable than the originally intended effect. That being said, I'd never grep someone in a void context myself. Larry
Re^5: Map Vs Foreach
by Jenda (Abbot) on Dec 01, 2009 at 17:06 UTC

    Using map in void context is like using print '' to obtain the number 1.

    Jenda
    Enoch was right!
    Enjoy the last years of Rome.