develooper Front page | perl.perl5.porters | Postings from July 2009

Re: [perl #67694] List::Util attaching to the wrong $_ when used inside given/when construct

Thread Previous | Thread Next
From:
Rafael Garcia-Suarez
Date:
July 21, 2009 03:02
Subject:
Re: [perl #67694] List::Util attaching to the wrong $_ when used inside given/when construct
Message ID:
b77c1dce0907210301q3416f1c1pbc337b0aaab2d4e1@mail.gmail.com
2009/7/21 Bram <p5p@perl.wizbit.be>:
> This seem to happen because given creates a lexical $_. It also happens when
> for/foreach is used with a lexical $_:

Hmm what ? No, given does not create a lexical $_ : from pp_entergiven :

    if (PL_op->op_targ == 0) {
        SV ** const defsv_p = &GvSV(PL_defgv);
        *defsv_p = newSVsv(POPs);
        SAVECLEARSV(*defsv_p);
    }
    else
        sv_setsv(PAD_SV(PL_op->op_targ), POPs);

(rewriting that with the proper macros will be nice) (not sure if
there is absolutely no bug there)

What happens, at first glance, it that List::Util always uses the
global $_. (an "our $_" in the "first" block should solve the pb).

We provide UNDERBAR and dUNDERBAR macros to access the current $_, be
it lexical or global.

However we don't have (yet) an API to localize the current $_ as
needed in grep-like functions.

I suppose that code from pp_grepstart could be copied in List::Util to
solve the bug.

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