http://www.perlmonks.org?node_id=1053101


in reply to Re^4: $_ functions vs argument-using functions
in thread $_ functions vs argument-using functions

Wow, thanks for the info!

( learned again something new in the universe of Perl's special cases... ;-)

update

so from a performance point of view there is no reason to prefer map f, 1..3 over map { g($_) } 1..3!

Cheers Rolf

( addicted to the Perl Programming Language)

Replies are listed 'Best First'.
Re^6: $_ functions vs argument-using functions
by tobyink (Canon) on Sep 09, 2013 at 22:40 UTC

    As I said, the block form does add a little overhead, because it creates a lexical scope. It's very minor though, so it's generally better to go with whatever you think is more readable.

    When you need to micro-optimize a tight loop that gets called millions or billions of times... that's when you start looking at removing unnecessary lexical scopes! The block forms of grep and map can be replaced with the expression forms; if/elsif/else chains can become ternary operator expressions; foreach blocks become statement modifiers; etc.

    use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name