develooper Front page | perl.perl5.porters | Postings from February 2013

Re: Salvaging lexical $_ from deprecation

Thread Previous | Thread Next
Aristotle Pagaltzis
February 20, 2013 12:46
Re: Salvaging lexical $_ from deprecation
Message ID:
* Ruslan Zakirov <> [2013-02-20 13:35]:
> grep is a special function with (&@) prototype

Only very notionally, not in any way in terms of how it really works.

> but this prototype doesn't describe it completly. It doesn't tell
> where to lookup $_ (and probably other variables) within the code
> block binded to & in the protototype.

The block in a `grep` is simply not a function. Consider what this does:

    sub foo { grep { return; 1 } 1..4 }

Then consider what this does:

    use List::Util 'reduce';
    sub foo { reduce { return; 1 } 1..4 }

(That difference is one of a number of reasons that Rafaƫl is wrong
in his response to me that such lightweight blocks would be useless
without lexical $_.)

Aristotle Pagaltzis // <>

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About