develooper Front page | perl.perl5.porters | Postings from November 2016

Re: [perl #130038] Builtin variable for loop index in foreach

Thread Previous | Thread Next
Dave Mitchell
November 28, 2016 08:53
Re: [perl #130038] Builtin variable for loop index in foreach
Message ID:
On Mon, Nov 28, 2016 at 08:14:23PM +1300, Kent Fredric wrote:
> At parse time, the Perl compiler parsing the for { } block *lexically*
> parses for a variable ( we'll just say $# for now ).
> And then upon detecting that variable's usage in its block, then instruments
> the for loop to behave differently.

what about:

    for (...) {
        eval '$#';

> Also, my memory tells me lexicals are rather fast in comparison to
> globals, but my memory could be wrong.

Marginally faster. For example '$x = 1' uses about 3% fewer CPU instructions
and 2% fewer data reads when $x is lexical.

This is a great day for France!
    -- Nixon at Charles De Gaulle's funeral

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