On Jul 24, 2009, at 4:10 PM, Rafael Garcia-Suarez wrote: > Graham, would you consider an improved version of the patch below for > List::Util, to make first work with lexical $_ ? I don't think there > are other areas in List::Util that need a similar modification. Sure. first is the only place in List::Util where $_ is used. This patch would work for the XS version, but what about the pure Perl ? Although should the code passed to first call a sub, that code will not see $_, but I suspect grep has the same issue there Graham. > > --- a/ext/List-Util/ListUtil.xs > +++ b/ext/List-Util/ListUtil.xs > @@ -329,16 +329,25 @@ CODE: > I32 gimme = G_SCALAR; > SV **args = &PL_stack_base[ax]; > CV *cv; > + PADOFFSET padoff_du = find_rundefsvoffset(); > + bool has_global_underbar = padoff_du == NOT_IN_PAD > + || PAD_COMPNAME_FLAGS_isOUR(padoff_du); > > if(items <= 1) { > XSRETURN_UNDEF; > } > cv = sv_2cv(block, &stash, &gv, 0); > PUSH_MULTICALL(cv); > - SAVESPTR(GvSV(PL_defgv)); > + if (has_global_underbar) > + SAVESPTR(GvSV(PL_defgv)); > + else > + SAVESPTR(PAD_SVl(padoff_du)); > > for(index = 1 ; index < items ; index++) { > - GvSV(PL_defgv) = args[index]; > + if (has_global_underbar) > + GvSV(PL_defgv) = args[index]; > + else > + PAD_SVl(padoff_du) = args[index]; > MULTICALL; > if (SvTRUE(*PL_stack_sp)) { > POP_MULTICALL; >Thread Previous | Thread Next