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

Re: Salvaging lexical $_ from deprecation

Thread Previous | Thread Next
From:
Aristotle Pagaltzis
Date:
February 20, 2013 12:46
Subject:
Re: Salvaging lexical $_ from deprecation
Message ID:
20130220124602.GA1942@fernweh.plasmasturm.org
* Ruslan Zakirov <ruz@bestpractical.com> [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 // <http://plasmasturm.org/>

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About