On Sun Apr 29 09:45:23 2012, Hugmeir wrote:
> On Tue Feb 24 14:12:49 2004, rjk-perl-p5p@tamias.net wrote:
> > On Tue, Feb 24, 2004 at 11:56:51AM -0500, Casey West wrote:
> > > It was Monday, February 23, 2004 when perl-5.8.0@ton.iguana.be (via
> > RT) took the soap box, saying:
> > > : perl -wle '@F="A".."BZ"; $_="a"; s/./<$F[@a="b"..$&]>/; print;
> > print"a=@a"'
> > > : Argument "b" isn't numeric in range (or flop) at -e line 1.
> > > : Use of uninitialized value in range (or flop) at -e line 1.
> > > : Use of uninitialized value in range (or flop) at -e line 1.
> > > : <B>
> > > : a=0
> > >
> > > If I add a /e modifier on the end of your s///, and fix up the
> > > replacement section, I get the following:
> > >
> > > perl -wle '@F="A".."BZ"; $_="a"; s/./join $F[@a="b"..$&], "<",
> > ">"/e; print; print"a=@a"'
> > > <Z>
> > > a=b c d e f g h i j k l m n o p q r s t u v w x y z
> > >
> > > : I expected $& to be "a", so @a should become (a b c ....z), so
> > fetch
> > > : element 26 from @F, which should be "Z"
> > >
> > > I think that I got what you expected. When you want to evaluate code
> > > in a regular expression you must add the /e modifier. I think that
> > > this is notabug. Am I missing something?
> >
> > Perl evaluates code inside array and hash indexes inside double-
> > quotish
> > strings. MJD takes advantage of this with his Interpolation module
> > (e.g. print "3 + 4 = $E{3+4}";). The warnings from Ton's example
> > indicate
> > that the flip flop operator is being executed; the bug is that $&
> > isn't
> > being set.
> >
> > Ronald
> >
>
> This is still present in blead, albeit behaving a tad differently:
> $ ./perl -wle '@F="A".."BZ"; $_="a"; s/./<$F[@a="b"..$&]>/; print;
> print"a=@a"'
> Use of uninitialized value $& in range (or flop) at -e line 1.
> <A>
> a=
>
> Strangely enough, you can get $& to work in the flipflop if it's
> evaluated beforehand somehow:
> $ ./perl -Ilib -wle '@F="A".."BZ"; $_="a"; s/./<$F[!!$& &&
> (@a="b"..$&)]>/; print; print"a=@a"'
> <Z>
> a=b c d e f g h i j k l m n o p q r s t u v w x y z
>
> Putting an sv_dump() after the SvGETMAGIC(right) in pp_flop gives us this:
> $ ./perl -Ilib -wle '@F="A".."BZ"; $_="a"; s/./<$F[@a="b"..$&]>/; print;
> print"a=@a"'
> [...]
> SV = PVMG(0x854ab74) at 0x855c02c
> REFCNT = 1
> FLAGS = (GMG,SMG)
> IV = 0
> NV = 0
> PV = 0
> MAGIC = 0x855d3f4
> MG_VIRTUAL = &PL_vtbl_sv
> MG_TYPE = PERL_MAGIC_sv(\0)
> MG_OBJ = 0x855c01c
> MG_LEN = 1
> MG_PTR = 0x855d314 "&"
> Use of uninitialized value $& in range (or flop) at -e line 1.
> <A>
> a=
>
>
> I don't know the first thing about magic or the regex engine, so I'm
> stopping here. Could someone take a peek?
I seem to remember looking into this before. IIRC, it has to do with
s/// guessing whether it needs to set up match information for the rhs
based on its op tree. Or something like that.
--
Father Chrysostomos
---
via perlbug: queue: perl5 status: open
https://rt.perl.org:443/rt3/Ticket/Display.html?id=26986
Thread Next